Solved

Script to reboot servers and check availability

Posted on 2013-11-15
4
267 Views
Last Modified: 2014-10-06
Hello,

I am after a script which will take an input file of servers and reboot them one by one.  I need to make sure that the servers have been rebooted successfully before moving onto the next one in the list.

Does anybody know if a script like that exists?
0
Comment
Question by:ukznmcl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 40

Accepted Solution

by:
Subsun earned 250 total points
ID: 39651075
To start with, you can use the following script to reboot the servers and check the uptime.. Increase the sleep time as per your convenience.

$Servers = GC C:\servers.txt
$creds = get-credential Domain\admin
restart-computer -CN $Servers -force -throttlelimit 10 -credential $creds
Sleep -Seconds 600 
$Servers | % {
$Server = $_
IF (Test-Connection $Server -Quiet){
	$wmi = Get-WmiObject Win32_OperatingSystem -ComputerName $Server
	$Uptime = $wmi.LocalDateTime - $wmi.LastBootUpTime
		New-Object PSobject -Property @{
		Server = $Server
		Uptime = $Uptime
		}
	}
Else{
		New-Object PSobject -Property @{
		Server = $Server
		Uptime = "Not Pinging"
		}		
	}
}

Open in new window

0
 
LVL 40

Assisted Solution

by:footech
footech earned 250 total points
ID: 39651548
How do you determine whether one has been rebooted successfully or not?  Just that you're able to ping it, or by some other criteria?  The Restart-Computer cmdlet in PS 3.0 includes a -wait parameter that can be set to check for remote PowerShell, WMI, or WinRM session (specified by the -for parameter), and wait for a positive response before moving on.  Check out the help for Restart-Computer for more detail.

To do one by one some adjustments would have to be made (just modifying Subsun's script).  I'm specifying to wait for WMI, as that is the first one available, and will still work even if you haven't set up PowerShell remoting on the target servers.
$Servers = GC C:\servers.txt
$creds = get-credential Domain\admin
foreach ($server in $servers)
{
   Restart-Computer -CN $server -force -credential $creds -wait -for WMI
}

Open in new window

0

Featured Post

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question