VMware Cloud Community
sagar666
Enthusiast
Enthusiast
Jump to solution

Powercli commands to get cluster info

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

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
sagar666
Enthusiast
Enthusiast
Jump to solution

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

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
sagar666
Enthusiast
Enthusiast
Jump to solution

Thanks a lot Lucd, for your explanation and script.

0 Kudos