Parity123
asked on
Powershell: Try/Catch help
Hello experts,
I have the following code
$mystring = @()
$DCName = "test1.net"
$ServiceName="spooler"
try { $mystring += Get-Service -ComputerName $DCName -Name $serviceName | Select name, Status }
Catch {
$mystring += "$DCName Error"
write-host "Error $DCName"
}
When the DC is down, and I cant connect to this DC, it does not go into the catch block, instead it throws the default error that Get-Service: cannot find any service .....
Please assist.
I have the following code
$mystring = @()
$DCName = "test1.net"
$ServiceName="spooler"
try { $mystring += Get-Service -ComputerName $DCName -Name $serviceName | Select name, Status }
Catch {
$mystring += "$DCName Error"
write-host "Error $DCName"
}
When the DC is down, and I cant connect to this DC, it does not go into the catch block, instead it throws the default error that Get-Service: cannot find any service .....
Please assist.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER