mimi m
mimi m

Reputation: 25

Get-Counter not working on certain servers to get average CPU Percent Utilization

This is my code:

(Get-Counter '\Processor(_Total)\% Processor Time').CounterSamples.CookedValue

I am trying to receive the average CPU Utilization with Get-Counter but every time i try i get this error message:

Get-Counter: The specified object was not found on the computer.

I have used the Get-WmiObject but that does not get me an accurate average.

When I run this command:

Get-WmiObject Win32_Processor | Measure-Object -Property LoadPercentage -Average | Select Ave

I get an output of 0 every time, but when I check on Task Manager, the CPU utilization percentage is not 0.

Also, I have searched for the answer to my problem and haven't been able to find one as all the answers that include Get-Counter don't work for me and throw an error message.

I even tried to troubleshoot the error:

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\%servicename%\Performance

But that gave me the error message:

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\%servicename%\Performance: The module 'HKEY_LOCAL_MACHINE' could not be loaded. For more information, run 'Import-Module HKEY_LOCAL_MACHINE'.

And when trying to run the Import-Module command, I got an error and reached another dead end

Upvotes: 1

Views: 33

Answers (1)

Ranadip Dutta
Ranadip Dutta

Reputation: 9173

As per I recall, on certain servers you have to manually rebuild it. The below article will give you the complete details:

Manually Rebuild Performance counters

Also, do check the registry entry first whether it is disabled or not:

  • 1 - Counter Disabled ,
  • 2 - 32 bit is only disabled ,
  • 4 - 64 bit is only disabled

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\%servicename%\Performance

Else re-build the counters and re-sync back. It is a must:

winmgmt.exe /RESYNCPERF

Hopefully this should help.

Upvotes: 0

Related Questions