VMware Cloud Community
bobby311
Enthusiast
Enthusiast

Powercli multiple get commands exported to a single CSV

Here is what I want in one single csv file:

get-vmhost, get-vm, get-resourcepool, get-datastore

I just want all of the information in a single csv, I attempted to use multiple pipes but that did not return the results I desired.

Any help is appreciated.

thanks!

0 Kudos
1 Reply
mattboren
Expert
Expert

Hello, bobby311-

Is it that you want the info in a single CSV file, or just in a single file at all?  The single CSV may not be super useful for automated reuse, as the data from the last three cmdlets would not correspond to the headers added to the CSV by the first cmdlet.

But, if you are wanting a CSV file that has separate sections, though, with headers for each section such that you could look at the file and glean info, you could run each command, exporting them to their own CSV, then add the content from the other CSVs to the first CSV, like:

## get the info, and put into separate CSVs for starters
Get-VMHost | Export-Csv -NoTypeInformation -UseCulture c:\temp\mainInfo.csv
Get-VM | Export-Csv -NoTypeInformation -UseCulture c:\temp\vmInfo.csv
Get-ResourcePool | Export-Csv -NoTypeInformation -UseCulture c:\temp\resourceInfo.csv
Get-Datastore | Export-Csv -NoTypeInformation -UseCulture c:\temp\dstoreInfo.csv

#
# put the info from the last three CSVs into the main CSV
"vm,resource,dstore".Split(",") | %{"" | Add-Content c:\temp\mainInfo.csv; Get-Content c:\temp\${_}Info.csv | Add-Content c:\temp\mainInfo.csv}

Again, that may not be a very handy CSV file for later importing back into PowerShell, but you could open it up and peruse the data you desired.  How's that?

0 Kudos