Hi,
I am writing script to generate report. I need commands to use script.
Cluster info to know total memory size and used size
Total VCPU count
Total VCPU cores count
Thanks
Try something like this
Get-Cluster |
Select Name,
@{N='Memory Total';E={$script:esx = Get-VMHost -Location $_; [math]::Round(($script:esx | Measure-Object -Property MemoryTotalGB -Sum | select -ExpandProperty Sum),0)}},
@{N='Memory Used';E={[math]::Round(($script:esx | Measure-Object -Property MemoryUsageGB -Sum | select -ExpandProperty Sum),0)}},
@{N='pCPU Total';E={$script:esx | %{$_.ExtensionData.Hardware.CPUInfo.NumCpuPackages} | Measure-Object -Sum | select -ExpandProperty Sum}},
@{N='pCore Total';E={$script:esx | %{$_.ExtensionData.Hardware.CPUInfo.NumCpuCores} | Measure-Object -Sum | select -ExpandProperty Sum}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try something like this
Get-Cluster |
Select Name,
@{N='Memory Total';E={$script:esx = Get-VMHost -Location $_; [math]::Round(($script:esx | Measure-Object -Property MemoryTotalGB -Sum | select -ExpandProperty Sum),0)}},
@{N='Memory Used';E={[math]::Round(($script:esx | Measure-Object -Property MemoryUsageGB -Sum | select -ExpandProperty Sum),0)}},
@{N='pCPU Total';E={$script:esx | %{$_.ExtensionData.Hardware.CPUInfo.NumCpuPackages} | Measure-Object -Sum | select -ExpandProperty Sum}},
@{N='pCore Total';E={$script:esx | %{$_.ExtensionData.Hardware.CPUInfo.NumCpuCores} | Measure-Object -Sum | select -ExpandProperty Sum}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Lucd,
Thanks a lot for your script it works great. Could you please explain what exactly below line will do so that, it will help in future to write similar scripts.
How do you getting Total memory. When i type in Powercli
Get-VMHost -Location Cluster1 I am not seeing memory fields and attached the screenshot for reference.
E={$script:esx = Get-VMHost -Location $_; [math]::Round(($script:esx | Measure-Object -Property MemoryTotalGB-Sum | select -ExpandProperty Sum),0)}},
Thanks
Sure, I'm storing the result of Get-VMHost n a variable $esx.
With the scope indication of 'script' i tell the PowerShell engine that he needs to retain this variable for the duration the script.
In other words, when the scripts ends, the variable will not exist anymore.
The reason I'm doing this, otherwise I would need to do a Get-VMHost for all the calculated properties.
When you do a Get-VMHost, not all properties are displayed by default.
What is displayed depends on the 'types' definitions, but also on for example on the dimensions of the console screen.
When you do
Get-VMHost -Location Cluster1 | Select *
you should see all properties on the returned objects.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks a lot Lucd, for your explanation and script.