powershell - 如何知道这个 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 是什么意思?非常感谢
解决方案
您提供的参数代表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"
推荐阅读
- colors - 如何修复此着色器以正确隐藏 Alpha 像素?
- javascript - 使用 JavaScript 换行以跨越 InnerText
- javascript - JS/Vue - 返回承诺异步问题
- python - 多个环境的 Django Cronjob 问题
- laravel - 从 Laravel 连接查询中选择同一个表中的多个列是否有更短的方法?
- laravel - laravel8 容器标签和标签不起作用
- python - 无法计算梯度下降线性回归
- google-apps-script - 使用替代运行时(NodeJS 后端)构建的 Gmail 插件有时会在插件上引发 HTTP 超时错误
- python - 旋转矩阵环第一行出错
- firebird - 如何在 Firebird 中评估数学表达式