VMware Cloud Community
alxta13
Contributor
Contributor

Get cluster details

hey all,

is there a way to add my command something that will pickup the cluster name on which the VM is located?

i use this to collect some data but cant find a way to add cluster name

$report = @()

foreach($vmlist in (Get-Content -Path C:\temp\PCLI\vmlist.txt)){

$vm = Get-VM -Name $vmlist

$report += (Get-VM $vm |

Select Name,NumCpu,MemoryGB,UsedSpaceGB,Guest)

}

$report | Export-Csv -Path C:\temp\PCLI\CPU_RAM_TTLPV_report.csv -NoTypeInformation -UseCulture

BR,

Alex

6 Replies
LucD
Leadership
Leadership

You can do that with a calculated property.

$report = @()

foreach($vmlist in (Get-Content -Path C:\temp\PCLI\vmlist.txt)){

    $vm = Get-VM -Name $vmlist

    $report += (Get-VM $vm |

        Select Name,NumCpu,MemoryGB,UsedSpaceGB,Guest,

            @{N='Cluster';E={(Get-Cluster -VM $_).Name}})

}

$report | Export-Csv -Path C:\temp\PCLI\CPU_RAM_TTLPV_report.csv -NoTypeInformation -UseCulture

And if you use the pipeline, you can do it like this

Get-VM -Name (Get-Content -Path C:\temp\PCLI\vmlist.txt) |

Select Name,NumCpu,MemoryGB,UsedSpaceGB,Guest,

    @{N='Cluster';E={(Get-Cluster -VM $_).Name}} |

Export-Csv -Path C:\temp\PCLI\CPU_RAM_TTLPV_report.csv -NoTypeInformation -UseCulture


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

alxta13
Contributor
Contributor

ok tnx that did the job Smiley Happy

one more thing plz

can the cluster be the first column in the report?

BR,

Alex

0 Kudos
LucD
Leadership
Leadership

Sure, just rearrange the properties on the Select

Get-VM -Name (Get-Content -Path C:\temp\PCLI\vmlist.txt) |

Select @{N='Cluster';E={(Get-Cluster -VM $_).Name}},

    Name,NumCpu,MemoryGB,UsedSpaceGB,Guest |

Export-Csv -Path C:\temp\PCLI\CPU_RAM_TTLPV_report.csv -NoTypeInformation -UseCulture


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

0 Kudos
alxta13
Contributor
Contributor

sorry my mistake Smiley Sad

i meant

NameClusterNumCpuMemoryGBUsedSpaceGBGuest
0 Kudos
LucD
Leadership
Leadership

You can arrange the properties on the Select as you prefer

Get-VM -Name (Get-Content -Path C:\temp\PCLI\vmlist.txt) |

Select Name,@{N='Cluster';E={(Get-Cluster -VM $_).Name}},

    NumCpu,MemoryGB,UsedSpaceGB,Guest |

Export-Csv -Path C:\temp\PCLI\CPU_RAM_TTLPV_report.csv -NoTypeInformation -UseCulture


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

alxta13
Contributor
Contributor

wow tnx for the free lesson Smiley Happy

0 Kudos