I am new to PowerShell, please bear with me. I was able to create a script to restart a computer and send email. I also setup to stop if it gets an error. (Ex. If computer is not on)
My question is there a way to create a PowerShell script to not email if the reboot command does not work then process the next command which is to restart another computer. The erroraction stops the entire script. Would it be better to create a script for each computer. I want to reboot 7 computers in one script and run in task scheduler.
restart-computer -computername “COMPUTER01” -force -wait -for wmi -delay 10 -erroraction stop
send-mailmessage -to “EMAILADDRESS” -from ANYNAME@GMAIL.COM -subject “Computer01 RESTARTED” -smtpserver “MAILSERVERNAME”
restart-computer -computername “COMPUTER02” -force -wait -for wmi -delay 10 --erroraction stop
send-mailmessage -to “EMAILADDRESS” -from ANYNAME@GMAIL.COM -subject “Computer02 RESTARTED” -smtpserver “MAILSERVERNAME”