First of all; Happy new year!
This script I’m about to show you is more of a workaround than a solution. Sometimes the recovery function for services is not enough to recover a service. I’ve found that in a number of occurrences the service doesn’t start successfully and stays in status “starting”. Windows doesn’t pick this up and the service stays in status “starting” until some third party monitoring software or someone else discovers the failed start.
Now as I wrote earlier this script is more of a workaround than a solution, but it has helped me more than once to serve as a quick-fix and buys some more time to get to the root cause of the issue.
# Check service status
$SrvName = "Service name"
# Enter the name of the service. E.g. "SQL Server Reporting Services (MSSQLSERVER)"
$ServiceStatus = Get-Service $SrvName
# Execute Start-Service or no action based on status of the service
if ( $ServiceStatus.status –eq "Running" )
{
Echo "No Action - The service is running"
}
ELSE
{
Echo "The service has status starting, stopping or stopped."
Echo "Attempting to start the service."
Start-Service -Name $SrvName
}
