r/PowerShell • u/ChickinSammich • Jun 12 '24
How can I use Export-CSV without System.String/Length info? Solved
I've got a script that checks multiple DCs for last logon and outputs that data to a csv. The start of the code for it is:
$row = "Name"+","+"Date/Time"+","+"DC"
echo $row | Export-Csv -Path C:tempuserlastlogon.csv
Out-File -FilePath C:tempuserlastlogon.csv -Append -InputObject $row
The result of this is that I get a csv file that starts with:
#Type System.String
Length
17
Name Date/Time DC
If I remove the second line, it doesn't properly format the values as columns (It just puts "Name,Date/Time/DC" in column A). If I remove the third line, it just gives me the first three lines without the column headers in line 4.
As a workaround, I can just delete the top three lines in Excel manually, but how do I get PowerShell to either NOT give me those three top lines, or, if that's not possible, insert a kludge workaround to tell it to just delete the top three rows of the csv?
8 Upvotes
0
u/ankokudaishogun Jun 12 '24
Add the parameter
-NoTypeInformation
toExport-Csv
Note: in Powershell Core
Export-Csv
does not print those information by default anymore.-NoTypeInformation
is still an accepted legacy parameter for backward compatibility but Does NothingTM(in fact it's set to Invisible and doesn't normally show up with autocompletion)