🐕

PSwatchdog

A PowerShell watchdog module for monitoring and automatically restarting processes, services, or script jobs — keep your automation running reliably.

⬇️ 0 Downloads
🏷️ v1.0.0 Version
📜 MIT License
Install: Install-Module -Name PSwatchdog
⬇️ PowerShell Gallery View on GitHub

Documentation

Overview

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.


Installation

Install from the PowerShell Gallery:

# Install for current user
Install-Module -Name PSwatchdog -Scope CurrentUser

# Import
Import-Module PSwatchdog

Quick Start

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

Commands

Start-Watchdog

Monitors a process by name and restarts it using the provided command if it stops.

ParameterTypeDefaultDescription
-ProcessNamestring(required)Name of the process to monitor
-Commandstring(required)Command used to start the process
-Argumentsstring""Optional arguments to pass to the command
-RestartDelayint5Seconds to wait before restarting
-MaxRestartsint0Maximum restart attempts (0 = unlimited)

Stop-Watchdog

Stops an active watchdog monitor.

ParameterTypeDescription
-WatchdogIdstringID of the watchdog returned by Start-Watchdog

Get-Watchdog

Lists all active watchdog monitors and their status.

Watch-Service

Monitors a Windows service and restarts it if it enters a stopped state.

ParameterTypeDefaultDescription
-Namestring(required)Service name to monitor
-RestartDelayint5Seconds to wait before restarting

Examples

Monitor a background process

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)"

Monitor a Windows service

Import-Module PSwatchdog

# Ensure the "DataIngestSvc" service stays running
Watch-Service -Name "DataIngestSvc" -RestartDelay 15

# List active watchdogs
Get-Watchdog

Limit restart attempts

# Restart at most 3 times, then give up
Start-Watchdog -ProcessName "flaky-app" `
               -Command "C:\apps\flaky-app.exe" `
               -MaxRestarts 3

Contributing

Contributions are welcome! See the GitHub repository for details.


License

PSwatchdog is released under the MIT License.

Related Blog Posts