Ive been banging my head on the desk trying to take a batch script and get the functionality in powershell.
I need to schedule reboots of servers and have the servers reboot one at a time according to the order of the file the server is in. I need to check a service or two, and then capture a log file for all servers in that specific scheduled reboot time, then email it out.
I am basically lost on this one entirely as I've tried all the options and I can schedule a single reboot, but nothing in a rolling manner, I can't get the logs or service checks to go, or the email.
Can anyone help me out? The batch file is old and it isn't great, but I'm also trying to learn more. All servers don't have powershell on them, and it's a mix of 2003-2012.
Do the services on the 1st server listen on a specific TCP port? You could have the second server do an while loop or do until those ports are back up and listening from the first server being rebooted and then trigger each dependent server in that manner.
emailing will only work if the SMTP server you're using alows the IP Address of the server sending the email to relay.
Also if the batch files work maybe you can post the batch file code here so we can look at it and show how it might be done with PowerShell.
Thank you for the response, I'm still working at this. The service I'm checking now is the RPC server and I found a better "batch file script" online than what I had so I am trying that, but it's still the same process basically and I think it could be better. I'd like the emails to be formatted so it's the server name – reboot start time – time server came back online, and anything else useful which I could add. I'm still trying to figure out how to do this in powershell and not having luck at all. One issue I have with this script is that I often get the "hang on reboot" alert emails and if I increase the time limit then it takes a long time to reboot the list of servers as some reboot quicker, I know I can't fix that as it's based on the server, but maybe a way to not have the hung reboot alerts unless it's really hung? I can send email from the system that I run this on.
REM Set the max time here for the time for the server to shutdown
REM End of Tunable Parameters
REM Finding the Local Timezone
REM Creating the temporary Log file
REM Checking if the list of servers for reboots is available.
REM Listing the servers that will be rebooted.
REM Subroutine to rename the temporary log file and then email the final log.
REM The actual reboot script.
REM Checking if server is up if it is not up, skip this server and go to the next one.
REM Rebooting the server.
for /L %%a in (1,1,%ST%) do (
for /L %%a in (1,1,%BT%) do (
for /L %%a in (1,1,%CT%) do (
I'll need some time to analyze the whole batch file but this first response I will just try to give you the PowerShell equivalents to some of your commands.
# TimeZone #
# append to a file instead of ECHO > #
# The for loop with content from a file #
# echo the date and time into your log file #
# Sending email #
# Checking is server is up # PING still works in PS #
# I showed rebooting remote servers above #
# interesting for /L # I am not familiar with what is in your %%a parameter #
# GOTO computerhung #
# ECHO text to user #
# Query a service # tragically not as powerful as SC #
look at using restart-computer with the -wait parameter – – that makes the process wait until the machine has rebooted.
you can start with this?
You could even throw in some test-connection statements etc
You must be logged in to reply to this topic.