VMware Cloud Community
dbutch1976
Hot Shot
Hot Shot
Jump to solution

Export multiple items of information to a single CSV file

Hi guys,

I'm trying to export information to a .csv file.  In the end I want the following information in the CSV with the following headers:

Name,NumCpu,MemoryMB,Description,NetworkName


I can get all the information for the first four headings (Name, NumCpu, MemoryMB, Description) with the following command:

Get-VM MYVM | select Name, NumCpu, MemoryMB, Description | Export-Csv -path "c:\outp\VMs.csv" -NoTypeInformation

To get the VLAN (aka NetworkName) I run the following command:

Get-VM MYVM | Get-NetworkAdapter | select NetworkName | Export-Csv "c:\output\VMs.csv" -NoTypeInformation

The command run successfully, however the second command is overwriting the information from the first one.  I have tried the -append switch which gives an error suggesting I use -force, which I have also tried, but the best I have been able to achieve is all the information being exported, but with unwanted spaces.  Is there an easy way to consolidate these two commands and export them to the csv file on the same line?

Thanks.

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Use a calculated property.

Try like this

Get-VM |

select Name, NumCpu, MemoryMB, Description,@{N='NetworkName';E={Get-NetworkAdapter -VM $_ | select -ExpandProperty NetworkName}} |

Export-Csv -path "c:\outp\VMs.csv" -NoTypeInformation


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
1 Reply
LucD
Leadership
Leadership
Jump to solution

Use a calculated property.

Try like this

Get-VM |

select Name, NumCpu, MemoryMB, Description,@{N='NetworkName';E={Get-NetworkAdapter -VM $_ | select -ExpandProperty NetworkName}} |

Export-Csv -path "c:\outp\VMs.csv" -NoTypeInformation


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos