How to Get Hyper-V CPU Information in Windows PowerShell

When asked to bring up a new server in an existing environment, I have to check three things to make sure we can handle it. The CPU available vs CPU assigned. RAM Available vs RAM Assigned and Storage Capacity. Now if you are working in a big environment you probably have the tools to spin up new machines quickly and easily but for Small Business environments this happens manually a lot of the time. Thus lest start with how to check the CPU information.

The below commands and images run directly from an RDP instance to a Server using PowerShell in Admin mode. There are various ways of getting the required information, as most IT users would know that sometimes the Examples don’t work in your environment for various reasons. There are many ways of getting the information. Specifically looking at the number of Logical cores.

SystemInfo

Systeminfo displays configuration information about a Computer. The detail is a bit lacking when trying to get detailed CPU information. See Example Below:

Hyper-V CPU Information
SystemInfo

Get-ComputerInfo

Next, you can run getcomputerinfo this will get you a list of System and Operating system Properties. This can then be refined to selected Objects only get-computerinfo | select-object *proc*. As per example, this server has 2 Physical CPUs with a collective of 32 logical processors.

Hyper-V CPU Information
Get-ComputerInfo

Get-VMHost

When running on a Hyper-V console the simplest would be to run Get-VMHost this actually gives you the exact information required and some detail on the RAM which will be handled in the following post.

Hyper-V CPU Information
Get-VMHost

Get-WMIObject

Following this, we can use the Windows Management Instrumentation (WMI). Powershell has a cmdlet called
Get-WmiObject which allows the use of WMI instances information. For this example, we can use the Win32_processor class.

Get-WmiObject -Class Win32_Processor | Select-Object -Property Name, Number*
Hyper-V CPU Information
Get-WMIObject

Win32_Processor

Note this shows NumberOfCores and NumberOfEnabledCore. The difference between the two option are explained on Microsoft site as Follows:

WMIC

We also should remember the defaults WMIC commands available in CMD. Even though this can be run in PowerShell.

WMIC CPU Get DeviceID,NumberOfCores,NumberOfLogicalProcessors
Hyper-V CPU Information
WMIC

Get-VMProcessor

Finally, it does not help we only have information on the Host machine. We need to know how many of the cores has been assigned the Virtual Machines running on the host. Simply use get-vmprocessor *

Hyper-V CPU Information
Get-VMProcessor

One thing to note, this shows the configs of all VM hosts. The example above shows a restored Machines. Which is actually not turned on only done as a test to make sure the backups run. A simple way to not see machines that are not in the running state is by using the GET-VM to check the VM State and only passing on Machines that are currently running.

Get-VM -VMName * | Where-Object {$_.State -eq 'Running'} | Get-VMProcessor | Select-Object -Property VMName,Count

Hyper-V CPU Information
Get-VM
Get-VMProcessor
Select-Object

If you want to get the CPU Information regardless of the VM State you can use the following command:

Get-VM -VMName * | Select-Object -Property VMName, State, @{Name = “CPU”; Expression = {get-vmprocessor -vmName $_.VMName | Select-Object -ExpandProperty count}}

********************************************************

If you liked what you read Please Share.
I’d love it if you followed me on YouTube and Facebook.

Also, feel free to subscribe to my posts by email.
Donations for the site can be made here.
Thanks for reading.

Spread the love

Leave a Reply

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