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
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
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
Perfect, many thanks!