0

I'm trying to display the number of context switches during one second in PowerShell. I've so far been trying the Get-Counter -Counter "System\Context Switches/sec" with both " " and ' ' and both leads to the error:

Get-Counter : Internal performance counter API call failed. Error: c0bc4

I'm aware of the perfmon's ability to show this, I need it displayed as text in Powershell.

Marcus Müller
  • 34,677
  • 4
  • 53
  • 94
Thomas
  • 315
  • 1
  • 5
  • 15

4 Answers4

2

You're missing a leading \. This will work:

get-counter -Counter "\System\Context Switches/sec"
arco444
  • 22,002
  • 12
  • 63
  • 67
  • Hi, I've tried this aswell, leading to same error-code. *edit* Almost same code -> c0bb9. – Thomas Mar 31 '15 at 10:03
  • Works fine for me. When I use the one in your question I get the same error code. Tried in all versions of powershell too and it works in each. Did you try running as administrator? – arco444 Mar 31 '15 at 10:08
  • Yes I've also ran it as administrator with same result, weird! – Thomas Mar 31 '15 at 10:18
2

Geeze, I just realized these commands are language-specific. My norwegian system only accepts norwegian commands. So that solves my problem!

Norwegian command: Get-Counter -Counter "\System\Kontekstvekslinger/sek"

Thomas
  • 315
  • 1
  • 5
  • 15
1

Try putting the computer name in the path.

get-counter -Counter "\\<computer-name>\System\Context Switches/sec"

Although the archo444 answer should work.

dimm
  • 1,792
  • 11
  • 15
0
$All = Get-Counter -ListSet * | ForEach-Object -Process { $PSItem.Paths; $PSItem.PathsWithInstances; }

get-counter -Counter ($All | Select-String -Pattern "context" )

i get same error like you i try like this and get result fine

Soheil
  • 837
  • 8
  • 17