VMware Cloud Community
mattbondie
Contributor
Contributor
Jump to solution

Script needed to count the number of Windows VM's per Cluster and the number of CPU cores

I've used the following one liner which gives me the numver of vm's per cluster but I need to narrow that down to just the number of Windows servers per cluster.

get-cluster | select @{n="cluster";e={$_.name}}, @{n="hosts";e={($_ | get-vmhost).count}}, @{n="vms";e={($_ | get-vm).count}} | sort cluster | ft -auto

I tried adding the following expression to select only Windows servers but it returns 0 for all vm's then.

get-cluster | select @{n="cluster";e={$_.name}}, @{n="hosts";e={($_ | get-vmhost).count}}, @{n="vms";e={($_ | get-vm | Where-Object {$_.OSFullName -like "*Windows Server*"}).count}} | sort cluster | ft -auto

Does anyone know what I'm doing wrong? I would also like to know the number of CPU cores used per cluster for the windows VM's.

Many thanks

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try like this.

Note that this requires the VMware Tools to be installed.

Get-Cluster |

Select-Object @{N="Cluster";E={$_.name}},

   @{N="Hosts";E={$_.ExtensionData.Host.Count}},

   @{N="WinVM";E={

    $script:winvm = $_ | Get-VM | Where-Object {$_.Guest.OSFullName -like "*Windows Server*"}

    $script:winvm.Count}},

   @{N='WinCPU';E={$script:winvm | Measure-Object -Property NumCpu -Sum | Select -ExpandProperty Sum}} |

Sort-Object -Property cluster |

Format-Table -AutoSize


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

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

Try like this.

Note that this requires the VMware Tools to be installed.

Get-Cluster |

Select-Object @{N="Cluster";E={$_.name}},

   @{N="Hosts";E={$_.ExtensionData.Host.Count}},

   @{N="WinVM";E={

    $script:winvm = $_ | Get-VM | Where-Object {$_.Guest.OSFullName -like "*Windows Server*"}

    $script:winvm.Count}},

   @{N='WinCPU';E={$script:winvm | Measure-Object -Property NumCpu -Sum | Select -ExpandProperty Sum}} |

Sort-Object -Property cluster |

Format-Table -AutoSize


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

0 Kudos
mattbondie
Contributor
Contributor
Jump to solution

Perfect, many thanks!

0 Kudos