Given: PowerShell 5.1
I’m getting an “Access denied” for some of the the computers in the array. How can make any errors run through the “else” part of condition where it’s NOT running? Right now, it’s just throwing entire error message and I don’t want the user to see all that.
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"
}
}