Check For Running Process
Check for a running process. If the process is not running, start it.
#CHECK RUNNING PROCESS
$Check = (Get-Service -Name <ServiceName> -ErrorAction SilentlyContinue -ErrorVariable ProcessError)
Invoke-Command -ScriptBlock{
if($Check -eq $null)
{
Write-host "<ServiceName> is not running" -ForegroundColor Red
Start-Service -Name <ServiceName>
Write-host "<ServiceName> was started" -ForegroundColor Yellow
}
else
{
Write-host "<ServiceName> is running" -ForegroundColor Yellow
}
}