Schedule a Servers reboot with email notification when are online

Schedule a servers restart it’s a healthy practice, it’s good for apply systems updates and it helps to free up memory. Thera are a lot of ways to do this, in this reminder i’ll show you wath I did. This example it works with Windows 2003, 2008, 2008r2, 2012, 2012r2, 2016…

First of all I chose one of our servers which is going to send the restart order to the rest, in my case i decided to use the main Domain controller, we have a huge number of server and not all of them can be restarted at same time, for this reason I made some restarting groups, you can do the same, the number it’s up to you.

For email notifications I decided to use SendEmail http://caspian.dotconf.net/menu/Software/SendEmail/ this is a free software which can sends emails using command line. You only have to download, and uncompress in a root folder, for example “C:\scripts”

I prepared a file called “reboot_alert_group1.cmd” a I placed in C:\scripts , Inside the file I placed an email notification similar than this

reboot_alert_group1.cmd


If you take a look of the script you’ll see there is no secret on it.

sendemail.exe -f “Sender email” -t “Destination Email” -u “Subject” -m “Body message” -s “SMTP Server adsress” -xu “Valid userto auth SMTP” -xp “Password of this user”

Then I prepared another file called restart_servers_group1.cmd, with this one I call reboot_alert_group1.cmd and then send the restart order using powershell to the servers.

restart_servers_group1.cmd

Before you can execute this I recommend to you to test the remote access to this servers using powershell, to do this, go to command line and run “powershell”. Take in mind to replace “Server01” with your destination server name that you want to test.

If all it’s Ok, it’s done, but if you get a connection error, probably you have to allow a “Remote Administration” from your IP in Server Firewall

Schedule the restarting tasks in this way, and repeat the process for every servers group

For notifications when servers are going to be online again we will use the same program SendEmail, and the only we are going to do is copy the SendEmail files in a root folder called C:\Script in every server and prepare a file with desired message. In my case I did with a file rebootalert.cmd

rebootalert.cmd

And then in this way we can prepare an Scheduled task that calls rebootalert.cmd when server starts.

 

 

That’ss all folks

Deixa un comentari

Your email address will not be published. Required fields are marked *