Genz
Rajesh Radhakrishnan
11/02/2018 Published 3 weeks ago
Share
https://vmarena.com/wp-content/uploads/2024/11/gradient-website-hosting-illustration_23-2149246882-1.jpg

Find Number of VCPU used in a Cluster and ESXi hosts

This Post explain how can we generate an output contains , Total number of vCpu used in an vCenter Cluster , also it shows many vCPU used per Esxi hosts .  If you have  multiple Cluster it is very easy to find same using below script.

Connect-VIServer  “vCenter Name”

$TotalNumvCPUs = 0
Foreach ($Cluster in (Get-Cluster |Sort Name)){
$HostNumvCPUs = 0
Write-Host “Cluster: $($Cluster.name)“
Foreach ($ESXHost in ($Cluster |Get-VMHost |Sort Name)){
Write-Host “ Host: $($ESXHost.name)“
$RunningLimit = $null
$RunningLimit = ($ESXHost |Get-VMHostAdvancedConfiguration).get_Item(“Misc.RunningVCpuLimit“)
If ($RunningLimit -eq $null){
$RunningLimit = 128
}
Write-Host “ Misc.RunningVCpuLimit: $RunningLimit“
Foreach ($VM in ($ESXHost |Get-VM)){
$HostNumvCPUs += ($VM).NumCpu
}
Write-Host “ Number of vCPU on host: $($HostNumvCPUs)“
$TotalNumvCPUs += $HostNumvCPUs
$HostNumvCPUs = 0
}
Write-Host “———-“
Write-Host “Number of vCPU in $($Cluster.name): $TotalNumvCPUs“
Write-Host “———-“
Write-Host “”
$TotalNumvCPUs = 0
}

Output