Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Powershell error handling when using DOS command mixed in

$
0
0

My shutdown script using the Shutdown -R command to do a mass reboot of
machines. If the Shutdown -R throws a error like "RPC Service Unavailable, or
access denied" I can't catch it or just don't know how to. Can someone help? I
don't want to use Restart-Computer in powershell since you can't delay the
reboot and can't add comments.

foreach($PC in $PClist){
ping -n 2 $PC >$null
if($lastexitcode -eq 0){  write-host "Rebooting $PC..." -foregroundcolor black -backgroundcolor green  shutdown /r /f /m \\$PC /d p:1:1 /t 300 /c "$reboot_reason"  LogWrite "$env:username,$PC,Reboot Sent,$datetime"
} else {  write-host "$PC is UNAVAILABLE" -foregroundcolor black -backgroundcolor red  LogWrite "$env:username,$PC,Unavailable/Offline,$datetime"
}
}


Any help would greatly be appreciated.

Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>