This is probably more “how PowerShell handles variables and pipes” than a specific programming question, but since it seems to me that this is a strange behavior (to me), I thought I would post it here.
I just had difficulty exporting the variable to CSV using PowerShell and found this question on Stack that helped me a lot . However, when I was busy with the exit, I got two different results, depending on what I called the function Export-CSV.
I have a custom PS object that looks something like this:
Account Partner ProjectName ProjectPhase
1 A Test Start
2 B Test2 Start
3 A Test4 End
4 C Test3 Middle
....
When I use the following line, it outputs the CSV file correctly:
$csvBody | Export-Csv -Path "$targetPath\$fileName" -Encoding Unicode -NoTypeInformation
However, when I use the following line, this is not the case:
Export-Csv -InputObject $csvBody -Path "$targetPath\$fileName" -Encoding Unicode -NoTypeInformation
: "", "LongLength", "", "SyncRoot", "IsReadOnly", "IsFixedSize", "IsSynchronized" 263, "263", "263", "1", "System.Object []", "", "True", "False"
Stack, $csvBody, . : , Export-CSV, , ?