通过任务计划程序执行时,Powershell脚本引发错误

时间:2020-03-23 10:41:01

标签: powershell get scheduled-tasks processor

我有一个powershell脚本,当我通过powershell或通过右键单击->使用powershell执行时,它可以很好地工作。 但是,当我尝试通过任务计划程序(以Admin身份并具有c的最高特权)执行它时,它将不起作用。

现在,我在脚本的开头添加了一个开始字幕“ ...”,并在日志中发现了该错误:

get-counter : Unable to connect to the specified computer or the computer is
offline.
At C:\directory\CPU.ps1:72 char:8
+ $CPU = get-counter -Counter "\\$env:computername\processor(_total)\%  ...
+        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidResult: (:) [Get-Counter], Exception
    + FullyQualifiedErrorId : CounterApiError,Microsoft.PowerShell.Commands.Ge
   tCounterCommand

这是整行,并引发错误: $ CPU = get-counter -Counter“ \ $ env:computername \ processor( total)\%Processor time” |选择-ExpandProperty CounterSamples |选择CookedValue | %{[Math] :: Round($ .CookedValue,2)}

有人知道,我该如何解决?

当我在powershell中或通过右键单击执行它时,没有错误。我不知道该怎么办。

0 个答案:

没有答案