Get number of cores (VCpu) per cpu and socket using PowerCLI

Spread the words

The following script audit the VM servers on an ESX host or a Vcenter for number of CPUs, sockets and CPU per socket. Then write the result on txt file.

$result = @()

$vms = Get-view  -ViewType VirtualMachine

foreach ($vm in $vms) {

$obj = new-object psobject

$obj | Add-Member -MemberType NoteProperty -Name ServerName -Value $vm.Name

$obj | Add-Member -MemberType NoteProperty -Name CPUs -Value $vm.config.hardware.NumCPU

$obj | Add-Member -MemberType NoteProperty -Name Sockets -Value ($vm.config.hardware.NumCPU/$vm.config.hardware.NumCoresPerSocket)

$obj | Add-Member -MemberType NoteProperty -Name CPUPersocket -Value $vm.config.hardware.NumCoresPerSocket

$result += $obj


$result | Out-File \\cifs\Share\cpuresult.txt

Connect to Vcenter using the Connect-VIServer cmdlet

Connect-VIServer –Server “vcenter name” –User “user name” –Password “user password”



Then run the script.


And here is the result.



Be the first to comment on "Get number of cores (VCpu) per cpu and socket using PowerCLI"

Leave a comment

Your email address will not be published.