Introducing PSwatchdog: Keep Your PowerShell Processes Running
Long-running PowerShell processes crash. PSwatchdog watches them and brings them back automatically — no babysitting required.
Read more →A PowerShell watchdog module for monitoring and automatically restarting processes, services, or script jobs — keep your automation running reliably.
PSwatchdog is a PowerShell module that monitors processes, services, or script jobs and automatically restarts them when they stop or become unresponsive. It helps keep your long-running automation tasks and critical services reliably running without manual intervention.
Install from the PowerShell Gallery:
# Install for current user
Install-Module -Name PSwatchdog -Scope CurrentUser
# Import
Import-Module PSwatchdog
Import-Module PSwatchdog
# Start watching a process and restart it if it stops
Start-Watchdog -ProcessName "myapp" -Command "C:\apps\myapp.exe"
# Watch a Windows service and restart it if it stops
Watch-Service -Name "MySvc" -RestartDelay 5
Start-WatchdogMonitors a process by name and restarts it using the provided command if it stops.
| Parameter | Type | Default | Description |
|---|---|---|---|
-ProcessName | string | (required) | Name of the process to monitor |
-Command | string | (required) | Command used to start the process |
-Arguments | string | "" | Optional arguments to pass to the command |
-RestartDelay | int | 5 | Seconds to wait before restarting |
-MaxRestarts | int | 0 | Maximum restart attempts (0 = unlimited) |
Stop-WatchdogStops an active watchdog monitor.
| Parameter | Type | Description |
|---|---|---|
-WatchdogId | string | ID of the watchdog returned by Start-Watchdog |
Get-WatchdogLists all active watchdog monitors and their status.
Watch-ServiceMonitors a Windows service and restarts it if it enters a stopped state.
| Parameter | Type | Default | Description |
|---|---|---|---|
-Name | string | (required) | Service name to monitor |
-RestartDelay | int | 5 | Seconds to wait before restarting |
Import-Module PSwatchdog
# Start a watchdog that keeps "worker.exe" running
$wd = Start-Watchdog -ProcessName "worker" `
-Command "C:\workers\worker.exe" `
-Arguments "--config prod.json" `
-RestartDelay 10
Write-Host "Watchdog started with ID: $($wd.Id)"
Import-Module PSwatchdog
# Ensure the "DataIngestSvc" service stays running
Watch-Service -Name "DataIngestSvc" -RestartDelay 15
# List active watchdogs
Get-Watchdog
# Restart at most 3 times, then give up
Start-Watchdog -ProcessName "flaky-app" `
-Command "C:\apps\flaky-app.exe" `
-MaxRestarts 3
Contributions are welcome! See the GitHub repository for details.
PSwatchdog is released under the MIT License.