Automation

 View Only
  • 1.  Number of VMs per cluster with New-VIProperty

    Posted Jun 13, 2014 12:19 PM

    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



  • 2.  RE: Number of VMs per cluster with New-VIProperty
    Best Answer

    Posted Jun 13, 2014 12:47 PM

    Have a look at my NumberOfVms property for Clusters.



  • 3.  RE: Number of VMs per cluster with New-VIProperty

    Posted Jun 13, 2014 12:56 PM

    Thanks a lot Luc that works perfectly.

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



  • 4.  RE: Number of VMs per cluster with New-VIProperty

    Posted Jun 13, 2014 01:06 PM

    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



  • 5.  RE: Number of VMs per cluster with New-VIProperty

    Posted Jun 13, 2014 01:13 PM

    Hi LucD,

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

    Frederic