Powershell Hypervisor WMI script to pull Available Processor Cores and Compare to Host HyperVisor Total Cores

I am looking to pull a list of the following :

  • #Total Count of Physical CPU Cores
  • #Total Count of In use CPU Cores
  • #Total Count of Available CPU Cores

In my Code Everything works except for

2018-03-08_9-22-13.png

#Total Count of Physical CPU Cores
#Total Count of In use CPU Cores
#Total COunt of Available CPU Cores

$cred = Get-Credential

$serverList =               Get-ADComputer -Filter "Name -like '*SERVER*'" |Sort-Object -Property Name |Select-Object -ExpandProperty Name

$HyperVFailoverInfo =           Invoke-Command -ComputerName $serverList -Credential $cred -ScriptBlock {
    $vMList =                   Get-VM
    $win32ProcessorList =       Get-WmiObject -Class Win32_Processor
    $TotalCPUCoresInUse =       ($vMList | Where-Object {$_.State -eq 'Running'} | Get-VMProcessor | Measure-Object -Property Count -Sum).Sum
    $logicalCpuCount =          (($win32ProcessorList | Measure-Object -Property NumberOfLogicalProcessors -Sum).Sum)
    $TotalAvailableCores =      [Math]::Round(($logicalCpuCount.count - $TotalCPUCoresInUse), 2)

    @{n = 'Total Processors';               e = {$logicalCpuCount}},
    @{n = 'TotalVirtualCPUsInUse';          e = {$TotalCPUCoresInUse}},
    @{n = 'Total Processors Available';     e = {$TotalAvailableCores}}

} |

Select-Object -Property * -ExcludeProperty PSComputerName, RunspaceId |
    Sort-Object -Property ComputerName, VMName
$HyperVFailoverInfo | Out-GridView

Open in new window

LVL 13
ITguy565Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ITguy565Author Commented:
Found a Typo in the original code, republished with proper code.
0
oBdACommented:
Still not the script that created the screenshot ...
You need to subtract the CPU count assigned to VMs from the total count; and rounding a subtraction of two integers is pointless.
Sorting the server list that's fed into Invoke-Command is pointless, too. Since the list is passed as a whole, the results can be returned in any order anyway.
#Total Count of Physical CPU Cores
#Total Count of In use CPU Cores
#Total COunt of Available CPU Cores

$cred = Get-Credential
$HyperVisorList =               Get-ADComputer -Filter "Name -like '*KH*HYP2*'" | Select-Object -ExpandProperty Name

$HyperVFailoverInfo =           Invoke-Command -ComputerName $serverList -Credential $cred -ScriptBlock {
	$logicalCpuCount =          (Get-WmiObject -Class Win32_Processor | Measure-Object -Property NumberOfLogicalProcessors -Sum).Sum
	$totalCPUCoresInUse =       (Get-VM | Where-Object {$_.State -eq 'Running'} | Get-VMProcessor | Measure-Object -Property Count -Sum).Sum
	$TotalAvailableCores =      [Math]::Round(($logicalCpuCount.count - $TotalCPUCoresInUse), 2)
	'' | Select-Object -Property `
		@{n = 'ComputerName';				e = {$ENV:ComputerName}},
		@{n = 'Total Processors';			e = {$logicalCpuCount}},
		@{n = 'TotalVirtualCPUsInUse';		e = {$TotalCPUCoresInUse}},
		@{n = 'Total Processors Available';	e = {$logicalCpuCount - $totalCPUCoresInUse}}
} |
	Select-Object -Property * -ExcludeProperty PSComputerName, RunspaceId |
	Sort-Object -Property ComputerName
$HyperVFailoverInfo | Out-GridView

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ITguy565Author Commented:
Thanks Yet again oBdA
0
ITguy565Author Commented:
Excellent Assistance!
0
oBdACommented:
Sorry, leftover from testing: line 11 ("$TotalAvailableCores = ...") isn't doing anything useful anymore and can be deleted.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.