VMware Cloud Community
fsosson
Contributor
Contributor
Jump to solution

Number of VMs per cluster with New-VIProperty

Hello,

I would like to get the number of VMs per cluster using New-VIProperty like this:

New-VIProperty -ObjectType VMHost -name NumberOfVMs `

  -Value {($Args[0] | Get-VM | Measure-Object).Count } `

  -Force

Get-Cluster | Select Name, NumberOfVMs

But I only get zeroes.

Can someone help me ?

Thanks,

Frederic

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Have a look at my NumberOfVms property for Clusters.


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

View solution in original post

Reply
0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

Have a look at my NumberOfVms property for Clusters.


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

Reply
0 Kudos
fsosson
Contributor
Contributor
Jump to solution

Thanks a lot Luc that works perfectly.

But on the same 'chapter' the NumvCPUs gives me empty values.  Have you experienced it ?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

That one needs the NumvCPUs on the VMHost object as well.

So you need to have both

New-VIProperty -ObjectType VMHost -name NumvCPUs `

-Value {

   $TotalvCPU = 0

   $Args[0] | Get-VM | foreach {

    $TotalvCPU += $_.NumCPU

   }

   $TotalvCPU

} -Force

New-VIProperty -Name NumvCPUs -ObjectType Cluster `

  -Value {

    $TotalvCPU = 0

    $Args[0] | Get-VMHost | foreach {

      $TotalvCPU += $_.NumvCPUs

    }

    $TotalvCPU

} -Force

Get-Cluster | Select Name, NumvCPUs


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

fsosson
Contributor
Contributor
Jump to solution

Hi LucD,

The part of code saved my day.  Thanks a lot.

Frederic

Reply
0 Kudos