Mark,
It takes a little work but not biggie.
Function ToCsv($v1, $v2, $v3) {
#Convert arguments to an Ordered Hash Table
$MyArgs = [Ordered]@{
Arg1 = "$v1"
Arg2 = "$v2"
Arg3 = "$v3"
}
#Convert the Hash table to a PS Custom Object.
$object = new-object psobject -Property $MyArgs
#Export the PS Custom Object as a CSV file.
Export-csv -InputObject $object -Path G:\BEKDocs\Test.csv -NoTypeInformation
}
ToCsv "One" "Two" "Three"
Results: (as seen in NP++)
"Arg1","Arg2","Arg3"
"One","Two","Three"
HTH
Update:
Here's a better solution that will handle any number of arguments.
Function ToCsv {
$ArgCnt = $Args.Count
$object = new-object psobject
For ($Cntr = 0; $Cntr -lt $ArgCnt; $Cntr++) {
$AMArgs = @{InputObject = $object
MemberType = "NoteProperty"
Name = $("Arg" + $($Cntr + 1))
Value = "$($Args[$($Cntr)])"
}
Add-Member @AMArgs
}
Export-CSV -InputObject $object -Path G:\BEKDocs\Test.csv -NoTypeInformation
} #End Function ToCSV
ToCsv "One" "Two" "Three" "Four"
Results: (as seen in NP++)
"Arg1","Arg2","Arg3","Arg4"
"One","Two","Three","Four"