VMware Cloud Community
bverm
Enthusiast
Enthusiast
Jump to solution

PowerCLI - Get number of cores per cpu and number of sockets

Greetings,

We are tasked with giving a list of all our VMs with their hostname, number of cpu's, OS and number of cores per cpu for an audit.

I immediately said this wouldn't be a problem with PowerCLI. However I seem to have more trouble with it than expected.

Getting the number of CPUs isn't a problem, but the moment I want to split the number of cores and the number of sockets I seem to hit a dead end.

I found the following relevant community entries:

Re: vSphere 5. vCPU Sockets and Cores per CPU bug (PowerCLI)

Acessing Virtual Machine Advanced Settings | VMware vSphere Blog - VMware Blogs

Retrieve and Set VM Advanced Configuration (VMX) settings

But neither seemed to give me the right entry. The advanced configuration settings don't seem to contain the number of cores/sockets and the normal Get-View and Get-VM commands don't seem to make a difference between cores and sockets and just give the number of CPUs.

Seeing as we need these settings for an audit I doubt I am the first to need this information. Does anybody have any idea how to get this information?

Please note it is the number of cores and sockets of a VM, not from an ESXi host. Smiley Happy

Thanks in advance,

Bram

1 Solution

Accepted Solutions
kunaludapi
Expert
Expert
Jump to solution

$result = @()
$vms = Get-view  -ViewType VirtualMachine
foreach ($vm in $vms) {
    $obj = new-object psobject
    $obj | Add-Member -MemberType NoteProperty -Name name -Value $vm.Name
    $obj | Add-Member -MemberType NoteProperty -Name CPUSocket -Value $vm.config.hardware.NumCPU
    $obj | Add-Member -MemberType NoteProperty -Name Corepersocket -Value $vm.config.hardware.NumCoresPerSocket
    $result += $obj
  
}
$result
--------------------------------------------------------------- Kunal Udapi Sr. System Architect (Virtualization, Networking And Storage) http://vcloud-lab.com http://kunaludapi.blogspot.com VMWare vExpert 2014, 2015, 2016 If you found this or other information useful, please consider awarding points for "Correct" or "Helpful".

View solution in original post

19 Replies
kunaludapi
Expert
Expert
Jump to solution

$result = @()

$vmhost = get-vmhost

foreach ($esxi in $vmhost) {

    $HostCPU = $esxi.ExtensionData.Summary.Hardware.NumCpuPkgs

    $HostCPUcore = $esxi.ExtensionData.Summary.Hardware.NumCpuCores/$HostCPU

    $obj = new-object psobject

    $obj | Add-Member -MemberType NoteProperty -Name name -Value $esxi.Name

    $obj | Add-Member -MemberType NoteProperty -Name CPUSocket -Value $HostCPU

    $obj | Add-Member -MemberType NoteProperty -Name Corepersocket -Value $HostCPUcore

    $result += $obj

}

$result

--------------------------------------------------------------- Kunal Udapi Sr. System Architect (Virtualization, Networking And Storage) http://vcloud-lab.com http://kunaludapi.blogspot.com VMWare vExpert 2014, 2015, 2016 If you found this or other information useful, please consider awarding points for "Correct" or "Helpful".
bverm
Enthusiast
Enthusiast
Jump to solution

Hello kunaludapi,

Thanks for the code, but I'm afraid that's just the cores and sockets from the ESXi host. For the audit we need the cores and sockets from the VMs. 😕

Kind regards,

Bram

Reply
0 Kudos
kunaludapi
Expert
Expert
Jump to solution

$result = @()
$vms = Get-view  -ViewType VirtualMachine
foreach ($vm in $vms) {
    $obj = new-object psobject
    $obj | Add-Member -MemberType NoteProperty -Name name -Value $vm.Name
    $obj | Add-Member -MemberType NoteProperty -Name CPUSocket -Value $vm.config.hardware.NumCPU
    $obj | Add-Member -MemberType NoteProperty -Name Corepersocket -Value $vm.config.hardware.NumCoresPerSocket
    $result += $obj
  
}
$result
--------------------------------------------------------------- Kunal Udapi Sr. System Architect (Virtualization, Networking And Storage) http://vcloud-lab.com http://kunaludapi.blogspot.com VMWare vExpert 2014, 2015, 2016 If you found this or other information useful, please consider awarding points for "Correct" or "Helpful".
bverm
Enthusiast
Enthusiast
Jump to solution

Thanks alot! That did it. Smiley Happy

Reply
0 Kudos
austing2k
Contributor
Contributor
Jump to solution

Hi Kunaludapi,

I am trying to pull up no. of sockets and number of cores per sockets. Would you please help in pulling up No. of virtual sockets.

The script you posted pulls up number of CPU's and number of CoresPerSockets? Is there any way I can pull up No. of Virtual sockets?

Thanks in advance,

Reply
0 Kudos
kwhornlcs
Enthusiast
Enthusiast
Jump to solution

Hi austing2k,

Virtual sockets is not directly provided by the API (or at least not that I could find), but with the properties that are provided and a slight change to the script can easily be calculated.

$result = @()

$vms = Get-view  -ViewType VirtualMachine

foreach ($vm in $vms) {

    $obj = new-object psobject

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

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

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

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

    $result += $obj

}

$result

Reply
0 Kudos
austing2k
Contributor
Contributor
Jump to solution

Thanks kwhornlcskwhornlcs for the reply.
I will try this one and keep you posted.

Reply
0 Kudos
austing2k
Contributor
Contributor
Jump to solution


Thanks kwhorncls. This is exactly what I was looking for. Smiley Happy. Sorry for the delayed reply. I did not get time to test this so long.

Reply
0 Kudos
SophiaSupport
Contributor
Contributor
Jump to solution

Hello,

Sorry for the stupid question but I'm really not familiar with PowerCli nor with programming and I must find out the same information for a customer and I don't know how to run this script... I tried to run it as a .pl after having installed the sdk for perl but it obviously lacks some code if run it as is... Is it even perl or what?

I'll be honest: my goal here is clearly not to learn how to make complicated scripts myself as I do not administrate ESX(i) servers, I just need to find out the number of cores then exploit the result I'll get into the product I support (which I know better how to do! :smileysilly:)

Thanks in advance for your help

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

There is a very good beginner's guide from XtraVirt.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

SophiaSupport
Contributor
Contributor
Jump to solution

Thanks but it leads me to a 404, even though I created an account.

EDIT: mmm I suppose this is it? http://xtravirt.com/media/2012/11/Beginners-Guide-to-Managing-VMware-using-Powershell.pdf (first result for a beginner's guide).

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I updated the link above, give it another try.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
miguelvelezwhit
Enthusiast
Enthusiast
Jump to solution

Just in case the updated link doesn't work, I just used this one and got to the page LucD is referring to:

http://xtravirt.com/kb/beginners-guide-to-managing-vmware-vi-using-powershell 

It's a PDF file of a white paper and what I've seen so far looks pretty good.

Good luck. Smiley Happy

Reply
0 Kudos
NavalgundRaj
Enthusiast
Enthusiast
Jump to solution

It worked for me too.thanks

Note: If you found this correct or answer useful please consider the use of the Correct buttons to award points. Regards Basavaraj.R Navalgund
Reply
0 Kudos
SophiaSupport
Contributor
Contributor
Jump to solution

Finally I was able to get information from VMs thanks to kwhornlcs's version althoug I get the list of VMs that are hosted along with the # of CPUs and sockets but can someone explain to me what could this information be usefull for "$vm.config.hardware.NumCPU/$vm.config.hardware.NumCoresPerSocket"? I'm not really sure I understand what it does... All I want is the # of virtual CPUs and the # of virtual cores for each VM.

Also I'd need the RAM  and eventually the OS that is installed etc. How do I get the list of parameters that are available to get this extra information, or do you know of a script that does that already?

----

Btw I'm trying to get even more information from the host... So if any of you can help on this thread: Need to get the name of the ESXi server, CPU, # of cores and RAM from Powercli

Reply
0 Kudos
pbalderos
Enthusiast
Enthusiast
Jump to solution

I am in the same boat trying to prepare for an audit. How can I get this info into a CSV or excel?

Please see my post from today.

Need a script to connect to vCenter, and get vCPU (vCPU, Sinfo on all virtual machines

Phillip Balderos VCP6-DCV
Reply
0 Kudos
kwhornlcs
Enthusiast
Enthusiast
Jump to solution

pbalderos, from script further up in this thread, change the last line to pipe to Export-CSV with a path and filename...for example:

$result | Export-CSV "c:\output\audit-info.csv" -notypeinformation

Legit82
Contributor
Contributor
Jump to solution

Hi Guys -

Im in the same boat now too using 5.5 & 6. Need to run a powercli script for CPU/CPU sockets/ RAM data. IS there an update for this?

Many Thanks!

Reply
0 Kudos
Legit82
Contributor
Contributor
Jump to solution

Hi Guys -

Im in the same boat now too using 5.5 & 6. Need to run a powercli script for CPU/CPU sockets/ RAM data. IS there an update for this?

Many Thanks!

Reply
0 Kudos