Virtu-Al.Net

Virtually everything is poshable

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
}

, ,

7 Responses to “PowerCLI: Number of vCPUs in a cluster”

  • q says:

    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!

  • Virtu-Al says:

    @q
    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.

  • RobSF says:

    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.

  • Chad King says:

    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.

  • Justin Smith says:

    How can I get the data to be output to a text file or html?

  • [...] I received a comment on an older post of mine which gave output of the number of virtual CPU’s on a host and also in a cluster, the comment [...]

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>