Solved

Script to reboot servers and check availability

Posted on 2013-11-15
4
268 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

734 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