0

I am new to power shell scripting. I am trying performance monitor commands for local machine in windows power shell with run as administrator.

PS C:\windows\system32> Get-Counter "\\$env:COMPUTERNAME\Processor(_total)\% Processor Time" -SampleInterval 5 -MaxSamples 5

But I am getting below error

Program 'Get-Counter' failed to run: No application is associated with the specified file for this operationAt line:1 char:1

Am unable to understand what is that error and why it is showing. I tried same command in another laptop, i am able to get response.

PavanKumar GVVS
  • 859
  • 14
  • 45
  • Get-Counter was first introduced in PS v3.0 (https://learn.microsoft.com/de-de/previous-versions/powershell/module/microsoft.powershell.diagnostics/get-counter?view=powershell-3.0) Make sure you have atleast version 3.0 installed. You can get your PS-Version with `$PSVersionTable.PSVersion`. – Paxz May 20 '20 at 12:14
  • My power shell version is 5.1 – PavanKumar GVVS May 20 '20 at 15:27
  • repair your windows counters. https://support.uptimesoftware.com/article.php?id=162 – Aaron May 21 '20 at 03:39
  • can you get that counter to list as part of the available sets? something like this >>> `(Get-Counter -ListSet 'processor' -ComputerName $env:COMPUTERNAME).Counter` << – Lee_Dailey May 21 '20 at 05:05
  • also, why do you have this tagged with `powershell-core`? your comment says you are running ps5.1 ... – Lee_Dailey May 21 '20 at 05:09
  • Lee, get-Counter itself failing. i tried same command in Windows powershell and also powershell and Windows Powershell ISE all powershell related. – PavanKumar GVVS May 21 '20 at 06:02
  • @Aaron, like you said i am thinking something is broken in my laptop. i tried "lodctr /r" resulted as "Info: Successfully rebuilt performance counter setting from system backup store" In the link you provided , i did first step but nothing works – PavanKumar GVVS May 21 '20 at 06:09

0 Answers0