Server Reboot Script – PS Job

Wrote this script today. I needed to reboot a server later and wanted to make sure it came back up. I plan to check it later, but wanted to get the response that it was up. Thought you folks might enjoy it. Maybe we can make it better. I want to add something to do the math so I can enter a time to reboot or possible the hours.

Critiques welcome.

<# This script will ask you what computer and what time you want to reboot it. Then schedule a job to do it. To do 1. service checkes? User can input services to check for after boot. #> $smtpServer = "smtpserver" $from = "fromaddress" $to = "toaddress" $computer = Read-Host "What computer do you want to reboot?" $time = Read-Host "Input time to wait for reboot, in seconds" $creds = Get-Credential $script ={ Start-Sleep -Seconds $using:time Restart-Computer $using:computer -Credential $using:creds -Wait -For Powershell -Timeout 600 -Delay 2 -Force if($? -eq $True) { $TC = ping $using:computer Send-MailMessage -SmtpServer $using:smtpServer -From $using:from -To $using:to -Subject "Server Reboot Successful" -Body "Computer/Server Rebooted<br/>$using:TC" -BodyAsHtml} else {Send-MailMessage -SmtpServer $using:smtpServer -From $using:from -To $using:to -Subject "Server Reboot Failed" -Body "Computer/Server Reboot Failed!<br/>$using:TC" -BodyAsHtml} } start-job $script -Credential $creds 

submitted by /u/spicyfreedomtacos
[link] [comments]

Leave a Reply