Qxlkdr
Qxlkdr

Reputation: 43

Windows Performance Monitor (PerfMon) not showing same value as corresponding WMI class

I have a PowerShell script to get all performance counters based on a list of WMI classes. However, the result of the PowerShell script is not consistent to what I see in Performance Monitor (PerfMon).

Here is an example PowerShell script that gives me both what PerfMon sees (via Get-Counter) and the result from WMI query:

$CounterName = "\xxxxxxxxxxxxx\xxxxxxxxxx-updates"
$WMIQuery = "SELECT * FROM Win32_PerfFormattedData_xxxxxxxxxx_xxxxxxxxxx"

while ($true) {
    $counterValue = (Get-Counter -Counter $CounterName).CounterSamples.CookedValue

    $perfData = Get-WmiObject -Query $WMIQuery

    $wmiCounterValue = $perfData.xxxxxxxx-updates

    Clear-Host

    Write-Host "Performance Counter:" -ForegroundColor Cyan
    $counterValue

    Write-Host "`nWMI Counter:" -ForegroundColor Cyan
    $wmiCounterValue

    Start-Sleep -Seconds 1
}

Here is an example result: enter image description here

Why are the result so much different when getting the data via WMI than using PerfMon or Get-Counter in PowerShell?

The "Performance Counter" value in the script is very consistent/even around 75-85 but the "WMI Counter" could be 0-200 during the same period of time.

We cannot use Get-Counter since it takes to much resources. If I would like to get 20 different performance counters using my script it would take approximately 1 second for each counter. Meaning the script would run around 20 seconds. Using WMI I can get the same amount in just 1-2 seconds.

The problem isn't getting counters using Get-Counter. The problem is that we're in a clustered environment which means that we would need to add -Credential to evaluate using a authenticated user and that process takes to long while using the Get-Counter method. This is why we prefer using the WMI class to SELECT * counters.

I assume that this is because PerfMon is showing an average and you get the same while using Get-Counter.

Have tried restarting winmgmt (Windows Management Instrumentation). Also tried running winmgmt /verifyrepository and it reports "WMI repository is consistent"

Or should I use the Raw Performance Counter Classes and do my own calculation?

How can I create a PowerShell script that uses Get-WmiObject -Query "SELECT * FROM xxxxx" to get the same result as shown in PerfMon?

Upvotes: 1

Views: 119

Answers (0)

Related Questions