How to Check if SharePoint services are started and with what account they are running

How to Check if SharePoint services are started and with what account they are running

Before you run a SharePoint script to do anything, it’s always good to check if all the required SharePoint services are running.  However, we often forget to do that, and when we get deployment errors, it takes awhile to find out that the timer service did not start.

Here is a script that you could put at the beginning of your SharePoint scripts, that tells you if the services are running, and lets you confirm before continuing the script.

#Script to Check if SharePoint Services are running.  www.vladcatrinescu.com

$ErrorActionPreference = “stop”
$sandbox = Get-WmiObject win32_service | Where-Object {$_.name -eq “SPuserCodeV4”}
$timer =  Get-WmiObject win32_service | Where-Object {$_.name -eq “SPTimerV4”}
$Trace = Get-WmiObject win32_service | Where-Object {$_.name -eq “SpTraceV4”}
if ($sandbox.State -eq “Stopped” -or $timer.State -eq “Stopped” -or $Trace.State -eq “Stopped” )
{
throw “A SharePoint Service is not running” 
}
else
{
Write-Host -ForegroundColor GREEN “All services  running”
Write-Host -ForegroundColor White $sandbox.name “is running with” $sandbox.StartName 
Write-Host -ForegroundColor White $timer.name “is running with” $timer.StartName 
Write-Host -ForegroundColor White $Trace.name “is running with” $Trace.StartName 
Write-Host -ForegroundColor Yellow “If everything is OK, press any key to continue. Else, Exit the script”
$x = $host.UI.RawUI.ReadKey(“NoEcho,IncludeKeyDown”)
}

Here is how it looks when all the services are running.   It tells you everything is running and also the service accounts they’re running under.

Here’s the error it throws when a service is not running.

Say thanks if it helped

No ratings yet.

Please rate this

 
Comments

Please, Can I have a copy of the script as downloadable file

regards

Hello,

Just copy it in notepad, then save it as a .ps1 !

Thanks!

Leave a Reply