Link to home
Start Free TrialLog in
Avatar of ITguy565
ITguy565Flag for United States of America

asked on

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

User generated image

#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

Avatar of ITguy565
ITguy565
Flag of United States of America image

ASKER

Found a Typo in the original code, republished with proper code.
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Yet again oBdA
Excellent Assistance!
Avatar of oBdA
oBdA

Sorry, leftover from testing: line 11 ("$TotalAvailableCores = ...") isn't doing anything useful anymore and can be deleted.