PowerShell script for rebooting a SP farm

I have written a little PowerShell script which you could use to reboot a multi server SharePoint farm.

# <#
# .DESCRIPTION
#     This script is for rebooting a moss farm with multiple servers.
#     The account must have Administrator privileges to reboot the server
# .NOTES
#     File Name  : reboot_moss_farm.ps1
#     Author     : Ronald Bruinsma @ iDocs.info
#     Requires   : PowerShell Version 2.0
# .LINK
#     This script posted to:
#         http://www.iDocs.info
#
# #>
# ##
# # Start of script
# ##

do {
# text var
$text_still_reachable = “server is still reachable and rebooting”
$text_not_reachable = “server is not reachable”
$text_up_running = “server is up and running again”

# ask user input
$super_user_input = read-host -prompt “domainname & accountname to use for the server reboot…”
$super_user = Get-Credential $super_user_input
$server_ip = read-host -prompt “Servername or IP number…”
$server1 = Get-WmiObject Win32_operatingsystem -computer $server_ip -credential $super_user

# reboot the server
$server1.reboot()

# ping the server while it is rebooting.
$ping = new-object System.Net.Networkinformation.Ping
write-host $server_ip $text_still_reachable -NoNewLine -ForegroundColor “Green”
do{$result = $ping.send($server_ip);write-host “.” -NoNewline -ForegroundColor “Green”}
Until($result.status -ne “Success”)
Write-host “”
write-host $server_ip $text_not_reachable -NoNewLine -ForegroundColor “Red”
do{$result = $ping.send($server_ip);write-host “.” -NoNewLine -ForegroundColor “Red”}
until ($result.status -eq “Success”)
Write-host “”
write-host $server_ip $text_up_running -NoNewLine -ForegroundColor “Green”
Write-host ” ”

# reboot another server? if yes, start all over again.
$strResponse = Read-Host “Do you want to reboot another server? (Y/N)”
}

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>