none
How do I get the number of physical and virtual processors on a virtual server RRS feed

  • Question

  • I have a script from Jesse Hamrick that gathers information about servers that I am altering to suit my needs. one of the things I need to gather is the number of physical and virtual processes on a virtual server. I've looked around and really don't see exactly what I'm looking for. Can someone here point me in the right direction, please? I am very new to PowerShell.


    Thank you!


    • Edited by MS Norkett Thursday, October 31, 2013 1:36 PM
    Thursday, October 31, 2013 1:36 PM

Answers

  • Hi,


    Please try it out..

    "" | Select @{n='TotalPhysicalProcessors';e={(,( gwmi Win32_Processor)).count}}, @{n='TotalPhysicalProcessorCores'; e={ (gwmi Win32_Processor | measure -Property NumberOfLogicalProcessors -sum).sum}}, @{n='TotalVirtualCPUs'; e={ (Get-VM | Get-VMProcessor | measure -Property Count -sum).sum }}, @{n='TotalVirtualCPUsInUse'; e={ (Get-VM | Where { $_.State -eq 'Running'} | Get-VMProcessor | measure -Property Count -sum).sum }}, @{n='TotalMSVMProcessors'; e={ (gwmi -ns root\virtualization\v2 MSVM_Processor).count }}, @{n='TotalMSVMProcessorsForVMs'; e={ (gwmi -ns root\virtualization\v2 MSVM_Processor -Filter "Description='Microsoft Virtual Processor'").count }}

    I'm using W2012 R2 Hyper-V with "root\virtualization\v2"

    In "MSVM_Processor" class, please note the host hypervisor also use Virtual CPUs. You can see in description property as "A logical processor of the hypervisor running on the host computer system.". In my lab, this (number of vCPUs used for hypervisor) is the same as total number of physical cpu cores.

    In the above example, I also used Hyper-V PS module (Get-VM, Get-VMProcessor). You need to import the module first. Noticed that the following two give the same result.

    (Get-VM | Where { $_.State -eq 'Running'} | Get-VMProcessor | measure -Property Count -sum).sum

    (gwmi -ns root\virtualization\v2 MSVM_Processor -Filter "Description='Microsoft Virtual Processor'").count


    ref for V2: MSVM_Processor

    ref for V1: MSVM_Processor

    EDIT: Just realize there are quite a number of changes in v1 and v2 virtualization name space.

    rgds,

    AZ



    • Edited by Neothwin Friday, November 1, 2013 8:24 AM added v1 link for msvm_processor class.
    • Marked as answer by AnnaWYModerator Wednesday, November 6, 2013 12:42 PM
    Friday, November 1, 2013 4:04 AM

All replies

  • Hi,

    Give this a try:

    Get-WmiObject Win32_ComputerSystem | Select NumberOfProcessors,NumberOfLogicalProcessors


    Don't retire TechNet! - (Maybe there's still a chance for hope, over 12,300+ strong and growing)

    Thursday, October 31, 2013 1:50 PM
    Moderator

  • gwmi win32_processor | ft Name, NumberOfCores, NumberOfLogicalProcessors -auto

    #or in PS 3 or 4

    Get-CimInstance win32_processor | ft Name,NumberOfCores,NumberOfLogicalProcessors -auto

    This works on Windows machines, physical or virtual.

    Please share with us if this helps. Thanks!

    • Edited by Desmond Lee Thursday, October 31, 2013 2:57 PM
    Thursday, October 31, 2013 2:56 PM
  • Ok -- I tried using gwmi Win32_NumberOfLogicalProcessors and gwmi Win32_NumberOfProcessors which is bringing back a number for each although I'm not certain it's the number I'm really looking for. What the script is bringing back is the same number for both and for some reason I feel like that should not be.

    What I did find in my research on the web uses a formula that doesn't use the Win32 class, but MSVM.

    • For each virtual processor for each currently running virtual machine there is an instance of the MSVM_Processor WMI object on the system.  So to figure out how many virtual processors are currently running – you just have to count how many instances of this WMI object are currently present on the system.
    • Summing up the NumberOfLogicalProcessors property of the Win32_Processor object will given you the other side of the calculation – namely how many logical processors are present in the system.

    gwmi -ns root\virtualization MSVM_Processor).count / (gwmi Win32_Processor) | measure -p NumberOfLogicalProcessors -sum).Sum)

    Thursday, October 31, 2013 5:09 PM
  • Hi,


    Please try it out..

    "" | Select @{n='TotalPhysicalProcessors';e={(,( gwmi Win32_Processor)).count}}, @{n='TotalPhysicalProcessorCores'; e={ (gwmi Win32_Processor | measure -Property NumberOfLogicalProcessors -sum).sum}}, @{n='TotalVirtualCPUs'; e={ (Get-VM | Get-VMProcessor | measure -Property Count -sum).sum }}, @{n='TotalVirtualCPUsInUse'; e={ (Get-VM | Where { $_.State -eq 'Running'} | Get-VMProcessor | measure -Property Count -sum).sum }}, @{n='TotalMSVMProcessors'; e={ (gwmi -ns root\virtualization\v2 MSVM_Processor).count }}, @{n='TotalMSVMProcessorsForVMs'; e={ (gwmi -ns root\virtualization\v2 MSVM_Processor -Filter "Description='Microsoft Virtual Processor'").count }}

    I'm using W2012 R2 Hyper-V with "root\virtualization\v2"

    In "MSVM_Processor" class, please note the host hypervisor also use Virtual CPUs. You can see in description property as "A logical processor of the hypervisor running on the host computer system.". In my lab, this (number of vCPUs used for hypervisor) is the same as total number of physical cpu cores.

    In the above example, I also used Hyper-V PS module (Get-VM, Get-VMProcessor). You need to import the module first. Noticed that the following two give the same result.

    (Get-VM | Where { $_.State -eq 'Running'} | Get-VMProcessor | measure -Property Count -sum).sum

    (gwmi -ns root\virtualization\v2 MSVM_Processor -Filter "Description='Microsoft Virtual Processor'").count


    ref for V2: MSVM_Processor

    ref for V1: MSVM_Processor

    EDIT: Just realize there are quite a number of changes in v1 and v2 virtualization name space.

    rgds,

    AZ



    • Edited by Neothwin Friday, November 1, 2013 8:24 AM added v1 link for msvm_processor class.
    • Marked as answer by AnnaWYModerator Wednesday, November 6, 2013 12:42 PM
    Friday, November 1, 2013 4:04 AM
  • Use the Get-VMHost cmdlet to the number of Processors on the host

    Use the Get-VM cmdlet to get the virtual processors on the virtual machine

    Saturday, May 16, 2015 4:02 PM