TheVMinator
Expert
Expert

Determing vCPU to Core ratios

Jump to solution

Is it possible to capture the number of cores on a physical host, then calculate the vCPU to core ratio using powerCLI?

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

Try something like this

Get-VMHost | Select Name,
 
@{N="pCores";E={$script:pCPU = $_.ExtensionData.Hardware.CpuINfo.NumCpuCores; $pCPU}},
 
@{N="vCores";E={
   
$script:vCPU = Get-VM -Location $_ | %{
     
$_.ExtensionData.Config.Hardware.NumCPU * $_.ExtensionData.Config.Hardware.NumCoresPerSocket
    }
| Measure-Object -Sum | Select -ExpandProperty Sum
   
$vCPU
  }}
,
 
@{N="Ratio vCore/pCore";E={[math]::Round(($script:vCPU/$script:pCPU),2)}}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
3 Replies
LucD
Leadership
Leadership

Try something like this

Get-VMHost | Select Name,
 
@{N="pCores";E={$script:pCPU = $_.ExtensionData.Hardware.CpuINfo.NumCpuCores; $pCPU}},
 
@{N="vCores";E={
   
$script:vCPU = Get-VM -Location $_ | %{
     
$_.ExtensionData.Config.Hardware.NumCPU * $_.ExtensionData.Config.Hardware.NumCoresPerSocket
    }
| Measure-Object -Sum | Select -ExpandProperty Sum
   
$vCPU
  }}
,
 
@{N="Ratio vCore/pCore";E={[math]::Round(($script:vCPU/$script:pCPU),2)}}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
shaggy_041086
Enthusiast
Enthusiast

Connect-VIServer $vcserver

$stats = @()

$Datacenter = Get-Datacenter

Foreach ($dc in $datacenter)

{

    $cluster = get-cluster -location $dc

    foreach ($cl in $cluster)

    {

    $row = New-Object System.Object

    $row | Add-Member -Type NoteProperty -Name "Name" -Value "$dc\$Cl"

        $ClusterVMs = $Cl | Get-VM

        $ClusterCPUCores = $Cl.ExtensionData.Summary.NumCpuCores

    $row | Add-Member -Type NoteProperty -Name "pCPU" -Value "$ClusterCPUCores"

    $ClusterAllocatedvCPUs = ($ClusterVMs | Measure-Object -Property NumCPu -Sum).Sum

    $row | Add-Member -Type NoteProperty -Name "vCPU" -Value "$ClusterAllocatedvCPUs"

    $ClusterRatio = 0

    $ClusterRatio = [math]::round($ClusterAllocatedvCPUs / $ClusterCPUCores,2)

    $row | Add-Member -Type NoteProperty -Name "Ratio" -Value " 1 : $ClusterRatio "

    $stats += $row

    }

}

$Stats = $Stats | Sort Ratio -Descending

TheVMinator
Expert
Expert

OK great thanks

0 Kudos