Functions/Get-HyperVCpuCommit.ps1


function Get-HyperVCpuCommit {
    [CmdletBinding()]
    param (
        # [Parameter(Mandatory)] [string] $Driveletter
    )


    $Result = [PSCustomObject]@{
        Total_HostCPUs = Get-CimInstance win32_processor | Select-Object -ExpandProperty NumberOfLogicalProcessors
        Total_vCPUs    = Get-VM | Get-VMProcessor | Measure-Object -Sum -Property Count | Select-Object -ExpandProperty Sum
        Active_vCPU    = Get-VM | Where-Object State -EQ "Running" | Get-VMProcessor | Measure-Object -Sum -Property Count | Select-Object -ExpandProperty Sum
    }


    if ($Result.Active_vCPU -ge $Result.Total_HostCPUs) {
        Write-Host "CPU overcommitted!" -ForegroundColor Red
    } else {
        Write-Host "CPU not overcommitted" -ForegroundColor Green
    }

    return $Result

}