Question

I asked this question on the TechNet forums without any luck (link), so I thought I'd see if anyone around here might have an answer:

At our company we have a VMM server (SCVMM 2012) controlling two physical Hyper-V hosts (let's call them HOST01 and HOST02). I'm trying to get some information about HOST01 via PowerShell queries on the VMM server:

Get-VMHost -ComputerName HOST01

..which among other things returns some CPU info:

...
LogicalProcessorCount = 12
PhysicalCPUCount = 1
CoresPerCPU = 12
L2CacheSize = 2048
L3CacheSize = 20480
BusSpeed = 100
ProcessorSpeed = 2294
ProcessorModel = Xeon
ProcessorManufacturer = Intel
ProcessorArchitecture = 9
ProcessorFamily = 179
CpuUtilization = 33
...

Now, I happen to know that HOST01 runs on a 6 core CPU with hyperthreading *), so LogicalProcessorCount = 12 is correct, but I expected to see CoresPerCPU = 6 (not 12). Why doesn't VMM show the correct number of physical cores? Am I looking in the wrong place?

Alternatively, is there a way to see whether hyperthreading is activated on the host, so I could divide by 2 as a last resort?

*) HOST01 is our own test server, so I have queried it separately through WMI to get CPU data, but in a production environment we cannot rely on having access to anything but the VMM server.

Was it helpful?

Solution

With Hyper-Threading enabled you get 2 logical processors per core. Since VMM cares only about the number of logical processors I doubt you'll be able to get "lower level" CPU information out of it. To get the actual number of cores for each CPU you have to query the processor information via WMI:

Get-WmiObject Win32_Processor -Computer HOST01 |
    select Name, NumberOfCores, NumberOfLogicalProcessors

Edit: In a situation where user and host have no access at all to the hypervisors I don't think you'll be able to obtain that information. Not without making some changes to the infrastructure, that is. The following might provide a viable approach, if you have someone who can set it up on the VMM host for you.

  1. Periodically collect the information from the hypervisors with a scheduled task running the following script on the VMM host:

    $datafile = 'C:\path\to\data.csv'
    $hypervisors = Get-SCVMHost | select -Expand Name
    Get-WmiObject Win32_Processor -Computer $hypervisors |
        select Name, NumberOfCores | Export-Csv $datafile -NoType -Encoding ASCII
    
  2. Publish the content of the datafile with a custom web server on the VMM host:

    $port       = 8000
    $datafile   = 'C:\path\to\data.csv'
    $lastUpdate = Get-Date 0
    $data       = ''
    
    function Get-Data {
      $filedate = (Get-Item $datafile).LastWriteTime
      if ($filedate -gt $lastUpdate) {
        $script:data = Import-Csv 'C:\Temp\text.csv' | ConvertTo-Json
        $script:lastUpdate = $filedate
      }
      $script:data
    }
    
    If (-not (Test-Path -LiteralPath $datafile)) {
      New-Item -ItemType File -Path $datafile | Out-Null
    }
    
    $listener = New-Object Net.HttpListener
    $listener.Prefixes.Add("http://+:$port/")
    $listener.Start()
    while ($listener.IsListening) {
      $response = $listener.GetContext().Response
      $response.Headers.Add('Content-Type', 'text/plain')
      $buffer = [Text.Encoding]::ASCII.GetBytes((Get-Data))
      $response.ContentLength64 = $buffer.Length
      $response.OutputStream.Write($buffer, 0, $buffer.Length)
      $response.Close()
    }
    $listener.Stop()
    

    If the Windows Firewall is enabled on the VMM host you need to open the listener port in it.

With that in place you can access the data from a server or workstation like this:

Invoke-WebRequest 'http://vmmserver:8000/' | select -Expand Content |
    ConvertFrom-Json
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top