首页 > 解决方案 > 如何知道这个 powerShell 命令中的 0 是什么意思?get-counter -Counter "\Process(0)\% Processor Time"

问题描述

我完全是 power-shell 的初学者,我读到你可以写,例如:

get-counter -Counter "\Process(powershell)\% Processor Time"

但是我收到了一个错误,我必须写,例如:

Get-Counter -counter "\\desktop-nrvk0ar\procesador(powershell)\% de tiempo de procesador"
Get-Counter : La ruta del contador de rendimiento \\desktop-nrvk0ar\procesador(powershell)\% de 
tiempo de procesador no es válida.
En línea: 1 Carácter: 1
+ Get-Counter -counter "\\desktop-nrvk0ar\procesador(powershell)\% de t ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidResult: (:) [Get-Counter], Exception
    + FullyQualifiedErrorId : CounterPathIsInvalid,Microsoft.PowerShell.Commands.GetCounterCommand

如果我写这样的数字,我不会收到错误:

get-counter -Counter "\Process(1)\% Processor Time"
get-counter -Counter "\Process(_total)\% Processor Time"

我怎么知道这个 0 或 1 或 _total 是什么意思?非常感谢

标签: powershellcpu-usage

解决方案


您提供的参数代表InstanceName您尝试从中收集信息的计数器。实例名称可能因Counters.

使用(Get-Counter -ListSet Process).PathsWithInstances命令获取有关Process计数器的信息。您也可以将此命令用于任何其他计数器。为了查看计数器的完整列表,只需使用Get-Counter -ListSet *

更多例子在这里

回到你的问题:

进程计数器期望参数是进程名称。这就是 (0, 1. _total) 不起作用的原因。

此示例将返回记事本的处理时间:

Get-counter -Counter "\Process(notepad)\% Processor Time"

编辑: 如果您尝试在远程计算机上运行命令,请添加计算机名称作为参数:

Get-counter -Counter "\Process(notepad)\% Processor Time" -ComputerName "computer_name"

推荐阅读