Skip to content

Script Monitor Documentation

Overview

This PowerShell script monitors the execution status of other .ps1 scripts in the same directory. It logs whether each script is running or not, checking every 60 seconds.

Prerequisites

  • PowerShell 7 (pwsh) installed on your system
  • Appropriate permissions to run PowerShell scripts

Usage

  1. Place this script in the same directory as the .ps1 scripts you want to monitor.

  2. Open a PowerShell terminal and navigate to the directory containing the scripts.

  3. Run the script:

    pwsh ./script_monitor.ps1
    

  4. The script will continuously monitor other .ps1 scripts in the directory, excluding itself.

  5. Results are logged to both the console and a file named "script_health_log.txt" in the same directory.

Features

  • Automatically detects all .ps1 scripts in the current directory
  • Excludes itself from monitoring
  • Checks script status every 60 seconds
  • Logs results with timestamps

Log Format

The log entries will have the following format:

YYYY-MM-DD HH:mm:ss - [ScriptName].ps1 is running.
YYYY-MM-DD HH:mm:ss - WARNING: [ScriptName].ps1 is not running!

Stopping the Monitor

To stop the script, press Ctrl+C in the PowerShell terminal where it's running.

Notes

  • Ensure that the monitored scripts are launched using the full path to pwsh.exe
  • The script uses the pwsh process name to identify running scripts, so it's designed for PowerShell 7 and later
  • Adjust the sleep interval (currently 60 seconds) if needed by modifying the Start-Sleep -Seconds 60 line