Category Archives: Scripting

Powershell – Reboot Servers listed in a txt file with delay

The following Powershell script will read a text file containing a list of systems to reboot (1 fqdn windows system per line), with a specified delay between each system.

<#
restart-computer (get-content c:\PSscripts\systemstoreboot.txt) -force
The above line has been spiffed up a bit to provide a delay between rebooting each system along with a status bar
#>
cls
write-host "If you wish, start up your monitoring/ping app to verify the restart of each system"
write-host "" # These lines are for spacing in the text version of powershell to display the status
write-host "" # In Powershell ISE you'll the spacing will appear more obvious.
write-host ""
write-host ""
write-host ""
write-host ""
write-host ""
write-host ""
get-content '\\server.mydomain.com\root\Gus\Scripts\PS\systemstoreboot.txt' | % {
 write-host "Restarting $_"
 restart-computer -ComputerName $_ -Force
$origtime=30 #match this time with $secs below to provide accurate percent complete 
for ($secs=30;$secs -gt 1; $secs--) {
 Write-Progress -id 1 -Activity "Pausing for 30 seconds between rebooting systems..." -SecondsRemaining $secs -Status "Please wait." -PercentComplete (($secs / $origtime) * 100)
 Start-Sleep 1
 } #close delay
 } #close get-content
 write-host "*** All Reboot commands have been issued ***"

Tested under Win8.1  with powershell version :

PS C:\PSScripts> $PSVersionTable

Name Value
—- —–
PSVersion 4.0
WSManStackVersion 3.0
SerializationVersion 1.1.0.1
CLRVersion 4.0.30319.34014
BuildVersion 6.3.9600.17400
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion 2.2