Hi everyone,
I'm trying to run a powercli command and export the results to a csv. I run the command below, but when I open the CSV all output is added into 1 Excel column, but there are 4 columns of data. Is there a way I can get it into excel, but each of the columns (name, powerstate, num cpus, memory) are in 4 Excel columns rather than 1?
get-vm | where-object {$_.powerstate -eq "poweredoff"} > c:\temp\poweredoffvms.csv
Thanks,
Scott
If its possible check bellow line
Get-VM | Where-Object {$_.PowerState -eq "PoweredOff"} | Export-Csv -Path c:\poweredoff-vms.csv -NoTypeInformation
And if you want just few items you can filter them by using "Select"
Get-VM | Where-Object {$_.PowerState -eq "PoweredOff"} | Select Name,PowerState,NumCPU,MemoryMB | Export-Csv -Path c:\poweredoff-vms.csv -NoTypeInformation
For exporting csv file you can use "Export-Csv"
If its possible check bellow line
Get-VM | Where-Object {$_.PowerState -eq "PoweredOff"} | Export-Csv -Path c:\poweredoff-vms.csv -NoTypeInformation
And if you want just few items you can filter them by using "Select"
Get-VM | Where-Object {$_.PowerState -eq "PoweredOff"} | Select Name,PowerState,NumCPU,MemoryMB | Export-Csv -Path c:\poweredoff-vms.csv -NoTypeInformation
For exporting csv file you can use "Export-Csv"
The previous reply is correct, pipe the objects to the Export-Csv cmdlet instead of redirecting them to a file.
One more remark, it's useful to add the UseCulture parameter on the Export-Csv cmdlet, that way the CSV will be created with the seperator as defined in your regional settings.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks for your help. That works perfect.
Is there a reason why when I use ">" to send the output to a file, it looks the same as it does in the powercli interface, however when I use export-csv, it exports tons of columns of data? Just curious.
Thanks,
Scott
Yes, the Export-Csv cmdlet reads the objects you place on the pipeline and converts them to the correct CSV format.
With the redirect (>), all is converted to 1 long string, and Excel considers this as 1 cell per line.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You can use ">>" to wrap each line you throw.
I think '>>' is used to append the data to an existing file.
And '>' will overwrite the file if it exists.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
yeah!
Thanks everyone for the help.