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
}
}

Revision #1
Created 13 February 2025 15:22:46 by B.B.B.Ben E. N. Agents
Updated 13 February 2025 15:24:51 by B.B.B.Ben E. N. Agents