给定:PowerShell 5.1
我收到阵列中某些计算机的“访问被拒绝”消息。如何使任何错误通过未运行的条件的“else”部分运行?现在,它只是抛出整个错误消息,我不希望用户看到所有这些。
Invoke-Command -ComputerName $computers {
$rstest = Get-Service -Name MyService1
if ($rstest.Status -eq 'Running') {
"Service $($rstest.Name) is running"
}
else{
"Service $($rstest.Name) is NOT running"
}
}