Get-Counter:负面分母?

时间:2012-07-20 17:02:14

标签: powershell

我正在运行此Powershell命令:

  

Get-counter -Counter" \ Processor(_Total)\%Processor Time" -Continuous

我在http://technet.microsoft.com/en-us/magazine/ee872428.aspx

上找到的

我用它来监视CPU,但是在运行它大约一分钟后发生了这个错误(导致它停止):

Get-Counter : A counter with a negative denominator value was detected.
At line:1 char:12
+ Get-counter <<<<  -Counter "\Processor(_Total)\% Processor Time" -Continuous
    + CategoryInfo          : InvalidResult: (:) [Get-Counter], Exception
    + FullyQualifiedErrorId : CounterApiError,Microsoft.PowerShell.Commands.GetCounterCommand

是什么导致这种情况发生的?我该怎么做才能防止这种情况发生,所以命令不会像这样中止(比如抑制错误)?

我无法定期重现这一点。

1 个答案:

答案 0 :(得分:0)

如果您的代码看起来像link中的示例,那么其他人似乎也有同样的问题。但是,这可能是您的环境的问题。这会发生在您拥有的每台电脑上吗?

powershell人似乎也有一些信息可以帮助你解决这个问题Powershell guy's blog。他基本上只是添加了这个命令-EA静默继续并导入计数器。