VMware Cloud Community
Chris_Bailey11
Contributor
Contributor

Combining two commands to output in a CSV

I have 2 commands I am trying to combine into a single script and output as a CSV for a number of servers listed in a separate text file. I can get each working in a script by itself, but I'm pulling my hair out getting them to play nice together.

The first is:-

(Get-VM -name VMName | select ExtensionData).ExtensionData.config | Select Name, MemoryHotAddEnabled,
CpuHotAddEnabled |Export-csv -NoTypeInformation Output.csv

 

Second:-

#(Get-VM -name VMName) | select name -ExpandProperty Customfields | where{$_.Key -eq 'Last Backup'}|
select Name, Value |Export-csv -NoTypeInformation Output.csv

 

TIA,

Chris

Reply
0 Kudos
1 Reply
LucD
Leadership
Leadership

You could do something like this

Get-VM -Name VMName |
Select Name,
    @{N='MemoryHotAddEnabled';E={$_.ExtensionData.Config.MemoryHotAddEnabled}},
    @{N='CpuHotAddEnabled';E={$_.ExtensionData.Config.CpuHotAddEnabled}},
    @{N='LastBackup';E={($_.CustomFields | where{$_.Key -eq 'Last Backup'}).Value}} |
Export-csv -Path Output.csv -NoTypeInformation -UseCulture


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