Connect-VIServer $vcserver
$stats = @()
$Datacenter = Get-Datacenter
Foreach ($dc in $datacenter)
{
$cluster = get-cluster -location $dc
foreach ($cl in $cluster)
{
$row = New-Object System.Object
$row | Add-Member -Type NoteProperty -Name "Name" -Value "$dc\$Cl"
$ClusterVMs = $Cl | Get-VM
$ClusterCPUCores = $Cl.ExtensionData.Summary.NumCpuCores
$row | Add-Member -Type NoteProperty -Name "pCPU" -Value "$ClusterCPUCores"
$ClusterAllocatedvCPUs = ($ClusterVMs | Measure-Object -Property NumCPu -Sum).Sum
$row | Add-Member -Type NoteProperty -Name "vCPU" -Value "$ClusterAllocatedvCPUs"
$ClusterRatio = 0
$ClusterRatio = [math]::round($ClusterAllocatedvCPUs / $ClusterCPUCores,2)
$row | Add-Member -Type NoteProperty -Name "Ratio" -Value " 1 : $ClusterRatio "
$stats += $row
}
}
$Stats = $Stats | Sort Ratio -Descending