PowerCLI to get Virtual to Physical CPU Ratio
I was in a meeting today, and was asked, “What is the current virtual to physical CPU ratio?” I didn’t have an answer for this question, so I asked PowerCLI for the answer.
[PS]
(get-cluster $ClusterName | Get-vm | Where Powerstate -eq “PoweredOn” | Measure NumCpu -sum).sum / (((Get-cluster $ClusterName | Get-vmhost).extensiondata.summary.hardware | Measure -Property numCpuCores -Sum).sum)
[/PS]
This will be a handy script that can be ran rather quickly. Below is the results of the script.
After a bit more of thought about this, I also wanted to get the VMhost Virtual to Physical ratio, so I reworked the script to get just that.
$report = @() $ClusterName = "ClusterName" $VMhosts = Get-cluster $ClusterName | Get-VMHost | Sort $PtoVRatio = (get-cluster $ClusterName | Get-vm | Where Powerstate -eq "PoweredOn" | Measure NumCpu -sum).sum / (((Get-cluster $ClusterName | Get-vmhost).extensiondata.summary.hardware | Measure -Property numCpuCores -Sum).sum) Write-host "Cluster $ClusterName has Physical to Virtual CPU Ratio of: $PtoVRatio" -BackgroundColor Black -ForegroundColor Yellow Foreach ($VMhost in $VMhosts){ $HostPtoVRatio = ($VMhost | Get-vm | Where Powerstate -eq "PoweredOn" | Measure NumCpu -sum).sum / ((($VMhost).extensiondata.summary.hardware | Measure -Property numCpuCores -Sum).sum) Write-Host "Host $($VMhost.name) Has Physical to Virtual CPU Ratio of: $HostPtoVRatio" -BackgroundColor Black -ForegroundColor Yellow }
Below is the output of the finalized script.
-Stuart