Here is a quick and easy way to restart all sharepoint services in your sharepoint server.
![pic]()
#Name of server where you are running the script
$server = "shop-01-FE"
#Listed are all the sharepoint services
$Services = "SPAdminV4", "SPSearchHostController", "OSearch15", "SPTimerV4", "SPTraceV4", "SPUserCodeV4", "SPWriterV4"
#Sleep Time between the service stop / start.
$sleepTime = 30
#Status of all sharepoint services before stop.....
"Status of all sharepoint services before stopping....."
"------------------------------------------------------"
foreach ($ServiceName in $Services) {
$x = (get-wmiobject -computer $server win32_service -filter "Name='$ServiceName'")
$Status = $x.Status
$State = $x.State
$ID = $x.ProcessId
"$ServiceName >> Status:$Status State:$State ServiceID:$ID"
$x.StopService() | out-null
}
"------------------------------------------------------"
#Stopping all sharepoint services
"****Stopping all sharepoint services****"
start-sleep -s $sleepTime
#ReStart Sharepoint Services
"****Re-starting all the sharepoint services****"
foreach ($ServiceName in $Services) {
$x = (get-wmiobject -computer $server win32_service -filter "Name='$ServiceName'")
$x.StartService() | out-null
}
start-sleep -s $sleepTime
#After gicing some time restart, double the status of sharepoint services again.
"Current Status of all sharepoint services after restart"
"------------------------------------------------------"
foreach ($ServiceName in $Services) {
$x = (get-wmiobject -computer $server win32_service -filter "Name='$ServiceName'")
$Status = $x.Status
$State = $x.State
$ID = $x.ProcessId
"$ServiceName >> Status:$Status State:$State ServiceID:$ID"
}
"------------------------------------------------------"
