Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Simple Logging Function

$
0
0

I was using the following commands in a loop to look for conditions and output a few variables to a CSV.

$object = New-Object -TypeName psobject -Property @{
UserName=$member.username
Path=$Path
Reason="blah blah blah"
}
$object | Export-Csv "$logpath\$dateTime.csv" -NoTypeInformation -Append

Worked great, however after pasting it into my script for the 10th time I decided it'd be smart to make a function out of it.

function Logger ($arg1, $arg2, $arg3)
{
$object = New-Object -TypeName psobject -Property @{
UserName=$arg1
Path=$arg2
Reason=$arg3
}
$object | Export-Csv "$logpath\$dateTime.csv" -NoTypeInformation -Append
}

Now for some reason I'm it's just outputting system.object[],, for every line.  I added some write-hosts to confirm that the args are being passed correctly, it's just not doing the export-csv correctly.  Is there something different about the way this works in a function?

Thanks,
Isaac


Viewing all articles
Browse latest Browse all 21975

Trending Articles