Restart Services Script

Looking for a PowerShell script to restart important services across a SharePoint farm? Look no further because all you need is here 🙂

The script below, initiated by calling the Restart-Services function, restarts the following services on all SharePoint servers in the farm:

  • SharePoint Timer
  • World Wide Web Publishing Service
  • IIS Admin Service
  • SharePoint Administration

function Restart-Services {
	[Array]$servers= Get-SPServer | ? {$_.Role -ne [Microsoft.SharePoint.Administration.SPServerRole]::Invalid}
	foreach ($server in $servers) {
		Restart-ServiceArray $server
function Restart-ServiceArray {
	param([parameter(Position=1, Mandatory=$true)][Microsoft.SharePoint.Administration.SPServer]$server)
	process {
		[Array] $services = "SPTimerV4", "W3SVC", "IISADMIN", "SPAdminV4"
		foreach($serviceName in $services) {
			$serviceInstance = Get-Service -ComputerName $server.Name -Name $serviceName -ErrorAction SilentlyContinue
	        	if($serviceInstance -ne $null) {
				Write-Host ("Restarting ", $serviceName, " on ", $server -join "")
				Restart-Service -InputObject $serviceInstance -Force
				Write-Host "Done`n" -ForegroundColor Green
			else {
				Write-Host ("Could not find ", $serviceName, " on ", $server -join "") -ForegroundColor Red

Simply add any additional services you want to restart to the $services array in the Restart-ServiceArray function and away you go!

This entry was posted in SharePoint and tagged , . Bookmark the permalink.
0 0 votes
Article Rating
Notify of

Solve the maths problem shown below before posting: *

Inline Feedbacks
View all comments