Automation

 View Only
Expand all | Collapse all

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

  • 1.  PowerCLI - Get number of cores per cpu and number of sockets

    Posted Mar 18, 2014 03:24 PM

    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. :smileyhappy:

    Thanks in advance,

    Bram



  • 2.  RE: PowerCLI - Get number of cores per cpu and number of sockets

    Posted Mar 18, 2014 04:52 PM

    $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



  • 3.  RE: PowerCLI - Get number of cores per cpu and number of sockets

    Posted Mar 19, 2014 07:01 AM

    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



  • 4.  RE: PowerCLI - Get number of cores per cpu and number of sockets
    Best Answer

    Posted Mar 19, 2014 07:14 AM
    $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


  • 5.  RE: PowerCLI - Get number of cores per cpu and number of sockets

    Posted Mar 19, 2014 07:29 AM

    Thanks alot! That did it. :smileyhappy:



  • 6.  RE: PowerCLI - Get number of cores per cpu and number of sockets

    Posted Feb 24, 2015 05:56 AM

    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,



  • 7.  RE: PowerCLI - Get number of cores per cpu and number of sockets

    Posted Mar 29, 2015 02:04 PM

    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



  • 8.  RE: PowerCLI - Get number of cores per cpu and number of sockets

    Posted Apr 02, 2015 04:41 PM

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



  • 9.  RE: PowerCLI - Get number of cores per cpu and number of sockets

    Posted May 07, 2015 06:54 AM


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



  • 10.  RE: PowerCLI - Get number of cores per cpu and number of sockets

    Posted Jan 20, 2017 02:31 PM

    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



  • 11.  RE: PowerCLI - Get number of cores per cpu and number of sockets

    Posted Jan 20, 2017 02:38 PM

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



  • 12.  RE: PowerCLI - Get number of cores per cpu and number of sockets

    Posted Jan 20, 2017 02:45 PM

    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).



  • 13.  RE: PowerCLI - Get number of cores per cpu and number of sockets

    Posted Jan 20, 2017 02:49 PM

    I updated the link above, give it another try.



  • 14.  RE: PowerCLI - Get number of cores per cpu and number of sockets

    Posted Jan 20, 2017 03:35 PM

    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. :smileyhappy:



  • 15.  RE: PowerCLI - Get number of cores per cpu and number of sockets

    Posted Jan 21, 2017 05:18 AM

    It worked for me too.thanks



  • 16.  RE: PowerCLI - Get number of cores per cpu and number of sockets

    Posted Jan 27, 2017 03:38 PM

    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



  • 17.  RE: PowerCLI - Get number of cores per cpu and number of sockets

    Posted Feb 17, 2017 09:40 PM

    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



  • 18.  RE: PowerCLI - Get number of cores per cpu and number of sockets

    Posted Feb 18, 2017 04:35 PM

    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



  • 19.  RE: PowerCLI - Get number of cores per cpu and number of sockets

    Posted Sep 13, 2017 10:26 PM

    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!



  • 20.  RE: PowerCLI - Get number of cores per cpu and number of sockets

    Posted Sep 13, 2017 10:55 PM

    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!