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
You can do that with a calculated property.
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
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
ok tnx that did the job
one more thing plz
can the cluster be the first column in the report?
BR,
Alex
Sure, just rearrange the properties on the Select
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
sorry my mistake
i meant
Name | Cluster | NumCpu | MemoryGB | UsedSpaceGB | Guest |
You can arrange the properties on the Select as you prefer
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
wow tnx for the free lesson