I am trying to accomplish getting the following stats put in a script.
When I run this script, it should be run per 'vcenter' and output the following.
Name of cluster / Number of hosts/ Number of VMs and Templates / Assigned Total Memory of all VMs on that cluster (not of what's actually being in use)
So for example, in cluster XYZ with 4 hosts, if I have 20 VMs that I have 4GB of RAM to each VM, the output should be 80GB
XYZ 4 20 80GB
I suspect you forgot the Select at the end to retrieve the sum.
@{N="CPU";E={
Get-View -Id (Get-View -Id $_.ExtensionData.Host -Property VM | %{$_.Vm}) -Property "Config.Hardware.NumCPU" |
%{$_.Config.Hardware.NumCPU} | Measure-Object -Sum | Select -ExpandProperty Sum}},
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try something like this
Get-Cluster |
Select Name,
@{N="Hosts";E={$_.ExtensionData.Host.Count}},
@{N="VM";E={
Get-View -Id $_.ExtensionData.Host -Property VM |
%{$_.Vm.Count} | Measure-Object -Sum | Select -ExpandProperty Sum}},
@{N="Memory (MB)";E={
Get-View -Id (Get-View -Id $_.ExtensionData.Host -Property VM | %{$_.Vm}) -Property "Config.Hardware.MemoryMB" |
%{$_.Config.Hardware.MemoryMB} | Measure-Object -Sum |
Select -ExpandProperty Sum
}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
great, should I use this to output it?
Export-Csv c:\report.csv -NoTypeInformation -UseCulture
Yes, you can pipe the results to the Export-Csv cmdlet
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Ok, I must be doing something wrong...here's the script...
Get-Cluster |
Select Name,
@{N="Hosts";E={$_.ExtensionData.Host.Count}},
@{N="VM";E={
Get-View -Id $_.ExtensionData.Host -Property VM |
%{$_.Vm.Count} | Measure-Object -Sum | Select -ExpandProperty Sum}},
@{N="Memory (MB)";E={
Get-View -Id (Get-View -Id $_.ExtensionData.Host -Property VM | %{$_.Vm}) -Property "Config.Hardware.MemoryMB" |
%{$_.Config.Hardware.MemoryMB} | Measure-Object -Sum |
Select -ExpandProperty Sum
}}
Export-Csv c:\report.csv -NoTypeInformation -UseCulture
I am guessing I am piping this wrong??? When I run it I get: cmdlet Export-Csv at command pipeline position 1, Supply values for the following paramenters: InputObject:
Those last 2 lines should be
}} | Export-Csv c:\report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Perfect, I guess I was just inserting it in the wrong place. Also, If I wanted to grab total CPU of each cluster, this doesn't work right...
Get-Cluster |
Select Name,
@{N="Hosts";E={$_.ExtensionData.Host.Count}},
@{N="VM";E={
Get-View -Id $_.ExtensionData.Host -Property VM |
%{$_.Vm.Count} | Measure-Object -Sum | Select -ExpandProperty Sum}},
@{N="CPU";E={
Get-View -Id (Get-View -Id $_.ExtensionData.Host -Property VM | %{$_.Vm}) -Property "Config.Hardware.NumCPU" |
%{$_.Config.Hardware.NumCPU} | Measure-Object -Sum |
@{N="Memory (MB)";E={
Get-View -Id (Get-View -Id $_.ExtensionData.Host -Property VM | %{$_.Vm}) -Property "Config.Hardware.MemoryMB" |
%{$_.Config.Hardware.MemoryMB} | Measure-Object -Sum |
Select -ExpandProperty Sum
}} | Export-Csv c:\report.csv -NoTypeInformation -UseCulture
I suspect you forgot the Select at the end to retrieve the sum.
@{N="CPU";E={
Get-View -Id (Get-View -Id $_.ExtensionData.Host -Property VM | %{$_.Vm}) -Property "Config.Hardware.NumCPU" |
%{$_.Config.Hardware.NumCPU} | Measure-Object -Sum | Select -ExpandProperty Sum}},
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Once again you have saved me...worked as you laid it out! Thanks! Again
Hello, I completely forgot to say I also needed the Datacenter Name as well. So would I add the following?
Get-Cluster |
Select Name,
Get-Datacenter |
Select Name,
That should work, just use the ExpandProperty parameter on the Select.
Get-Cluster -VMHost $_ | Select -ExpandProperty Name
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Once again, I must be doing something wrong. I am running PowerCLI 5.1 R2 and it states a parameter cannot be found 'VMHost'. Here's the script....
Get-Datacenter |
Select Name,
Get-Cluster -VMHost $_ | Select -ExpandProperty Name
Select Name,
@{N="Hosts";E={$_.ExtensionData.Host.Count}},
@{N="VM";E={
Get-View -Id $_.ExtensionData.Host -Property VM |
%{$_.Vm.Count} | Measure-Object -Sum | Select -ExpandProperty Sum}},
@{N="Memory (MB)";E={
Get-View -Id (Get-View -Id $_.ExtensionData.Host -Property VM | %{$_.Vm}) -Property "Config.Hardware.MemoryMB" |
%{$_.Config.Hardware.MemoryMB} | Measure-Object -Sum |
Select -ExpandProperty Sum
}} | Export-Csv c:\report2.csv -NoTypeInformation -UseCulture
I want the list to include the datacenter and the cluster.
I have tried the select expand property numerous ways and I just cannot get it to work. Still get the VMHost error. What am I doing wrong?
You need to do that in a calculated property.
Something like this
Get-Cluster |
Select Name,
@{N="Datacenter";E={Get-Datacenter -Cluster $_ | Select -ExpandProperty Name}},
@{N="Hosts";E={$_.ExtensionData.Host.Count}},
@{N="VM";E={
Get-View -Id $_.ExtensionData.Host -Property VM |
%{$_.Vm.Count} | Measure-Object -Sum | Select -ExpandProperty Sum}},
@{N="Memory (MB)";E={
Get-View -Id (Get-View -Id $_.ExtensionData.Host -Property VM | %{$_.Vm}) -Property "Config.Hardware.MemoryMB" |
%{$_.Config.Hardware.MemoryMB} | Measure-Object -Sum |
Select -ExpandProperty Sum
}} | Export-Csv c:\report2.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I tried that and no luck. The output shown below doesn't give me any Datacenter label. I have attached an image to show.
Would it be easier if we had Datacenter in the first column, and then cluster in the second column?
Which PowerCLI version are you using ? Do a
Get-PowerCLIVersion
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
5.1 R2, Build 1012425
That explains, the Get-Datacenter cmdlet with the Cluster parameter was introduced later.
Can you upgrade to PowerCLI 5.5 R2 ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I could be wrong, but isn't there a minus sign missing in the command?
<<< ... Get-Datacenter Cluster $_ ...
>>> ... Get-Datacenter -Cluster $_ ...
André