15 49.0138 8.38624 1 0 4000 1 https://vladtalkstech.com 300 1
theme-sticky-logo-alt

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

4 Comments

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

Previous Post
Unknown SQL Exception 297 occurred. Additional error information from SQL Server is included below.
Next Post
How to Make sure a Solution is added before Activating it

4 Comments

  • August 4, 2014 at 9:06 am
    Vamshi

    I encountered below error when i tried to run the script.
    -eq : You must provide a value expression on the right-hand side of the ‘-eq’ o
    perator.
    + CategoryInfo : ParserError: (:) [], ParseException

    Reply
    • August 10, 2014 at 11:34 am

      Hey,

      That’s really strange. are you sure the quotes and everything copied successfully? Also, on what line you got the error?

      Thanks,

      Reply
  • March 19, 2015 at 2:06 am
    baig

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

    regards

    Reply
    • March 20, 2015 at 1:32 am

      Hello,

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

      Thanks!

      Reply

Leave a Reply