PowerCLI: Number of vCPUs in a cluster

Inspired by Jason Boche’s article: http://www.boche.net/blog/index.php/2009/08/18/hidden-virtual-cpu-limit-restriction-in-esx-3-5/ and also William Lam’s Perl Script (http://communities.vmware.com/docs/DOC-10556).  I decided to re-create this in PowerCLI.

If you haven’t seen William’s scripts, I strongly suggest you check out the Perl Sample code where he stores them here: http://communities.vmware.com/community/developer/codecentral/vsphere_perl, he has been coding mad recently and turning out some really good stuff.

The PowerCLI script gives the following output:

Cluster: Production
Host: vmgesx01.vmguru.com
Misc.RunningVCpuLimit: 128
Number of vCPU on host: 4
Host: vmgesx02.vmguru.com
Misc.RunningVCpuLimit: 128
Number of vCPU on host: 3
Host: vmgesx03.vmguru.com
Misc.RunningVCpuLimit: 128
Number of vCPU on host: 2
Host: vmgesx04.vmguru.com
Misc.RunningVCpuLimit: 128
Number of vCPU on host: 5
Number of vCPU in Production: 14

And the code is below:

Connect-VIServer testviserver

$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

9 thoughts on “PowerCLI: Number of vCPUs in a cluster

  1. Pingback: Number of Physical & Virtual CPU’s per host & Cluster « « Virtu-AlVirtu-Al

  2. Chad King

    Coudln’t get this to work – is there an update to this script or how should I run this script? I apologize am recently new to the powerCLI and the community. I just got VCP and definitly need to work on my CLI skills with ESXi coming. Much help appreciated.

  3. RobSF

    It turns out that you can also increase the limit via PowerCLI. If you add the following code into Al’s script:
    If ($RunningLimit -lt 192){
    Write-Host ” CHANGING to 192….”
    $ESXHost |Set-VMHostAdvancedConfiguration -Name “Misc.RunningVCpuLimit” -Value 192
    … right after the line that displays the limit, then you can raise the limits on all of your hosts.

  4. Virtu-Al

    Good idea, easily added to this script, I will update it. I am going to include some memory and cpu stats in the daily report but contension is already covered by %RDY, after all you could have hundreds of under utilised vms on a host and all be fine.

  5. q

    How would we add the number of physical CPU cores per host and per cluster? The ratio of vCPUs to pCPUs describes CPU oversubscription and is useful when troubleshooting some performance issues… Might even be a useful addition to the daily report! 🙂 Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.