我有一个小的PowerShell脚本,我想通过Nagios监控执行验证,如果某个目录存在是或否。在Powershell ISE中调试和/或运行脚本时,每件事都可以,并产生所需的结果。通过Nagios安排脚本时,我收到了拒绝访问权限#34;错误。
脚本中产生错误的行:
$testJob = Start-Job -scriptblock {test-path $($args[0])} -credential $ipmamCredentials -argumentlist $ipmamdir
$finished = Wait-Job $testJob
$result = Receive-Job $testJob
Nagios产生的错误:
Receive-Job : [localhost] There is an error launching the background process. Error reported: Access is denied.
At C:\Program Files\NSClient++\scripts\check_ipmam_drives.ps1:19 char:26
+ $result = Receive-Job <<<< $testJob
+ CategoryInfo : OpenError: (:) [Receive-Job], PSRemotingTransportException
+ FullyQualifiedErrorId : PSSessionStateBroken