- Complete PowerShell-based monitoring solution for Windows reboots - Detects startup, shutdown, and unexpected restart events - Rich Discord notifications with color-coded alerts - Automatic reboot reason detection (Windows Update, power loss, user-initiated) - Task Scheduler integration for reliable event monitoring - Comprehensive setup instructions and troubleshooting guide 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
4.0 KiB
4.0 KiB
Windows Reboot Monitor Setup Instructions
This guide will help you set up Discord notifications for Windows reboots due to updates, power outages, or other events.
Prerequisites
-
Discord Webhook URL: Create a webhook in your Discord server
- Go to Server Settings → Integrations → Webhooks
- Create a new webhook and copy the URL
-
Administrator Access: Required to set up scheduled tasks
Installation Steps
Step 1: Create Scripts Directory
# Run as Administrator
New-Item -ItemType Directory -Path "C:\Scripts" -Force
Step 2: Copy PowerShell Script
- Copy
windows-reboot-monitor.ps1toC:\Scripts\ - Set execution policy (if needed):
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine
Step 3: Configure Discord Webhook
Option A - Environment Variable (Recommended):
# Set system environment variable
[Environment]::SetEnvironmentVariable("DISCORD_WEBHOOK_URL", "YOUR_WEBHOOK_URL_HERE", "Machine")
Option B - Direct parameter:
- Edit the Task Scheduler XML files to include your webhook URL in the arguments
Step 4: Import Scheduled Tasks
# Import startup monitoring task
schtasks /create /xml "C:\path\to\windows-reboot-task-startup.xml" /tn "Discord Reboot Monitor - Startup"
# Import shutdown monitoring task
schtasks /create /xml "C:\path\to\windows-reboot-task-shutdown.xml" /tn "Discord Reboot Monitor - Shutdown"
Step 5: Test the Setup
# Test startup notification
C:\Scripts\windows-reboot-monitor.ps1 -EventType "startup"
# Test shutdown notification
C:\Scripts\windows-reboot-monitor.ps1 -EventType "shutdown"
What You'll Get
Startup Notifications (Green/Red)
- Green: Normal startup with boot reason and uptime info
- Red: Unexpected restart (power loss, crash, etc.)
Shutdown Notifications (Yellow)
- System going offline with uptime and shutdown reason
Information Included
- Computer name
- Timestamp
- Boot/shutdown reason (Windows Update, power loss, user initiated)
- System uptime
- Startup counter
Troubleshooting
Check Logs
View logs at: C:\Windows\Temp\reboot-monitor.log
Verify Tasks are Running
# List scheduled tasks
Get-ScheduledTask | Where-Object {$_.TaskName -like "*Discord Reboot*"}
# Check task history
Get-WinEvent -LogName "Microsoft-Windows-TaskScheduler/Operational" | Where-Object {$_.LevelDisplayName -eq "Error"}
Test Discord Webhook
# Manual test
$webhook = "YOUR_WEBHOOK_URL"
$payload = @{content = "Test message from Windows"} | ConvertTo-Json
Invoke-RestMethod -Uri $webhook -Method Post -Body $payload -ContentType "application/json"
Common Issues
- PowerShell Execution Policy: Run
Set-ExecutionPolicy RemoteSigned - Network Issues: Ensure Windows can reach Discord (discord.com)
- Permissions: Run PowerShell as Administrator for setup
- Webhook URL: Verify the Discord webhook URL is correct
Event Log Monitoring
The script monitors these Windows events:
- Event ID 1074: System shutdown/restart
- Event ID 6008: Unexpected shutdown
- Boot events: System startup
Security Notes
- Script runs with SYSTEM privileges for reliable monitoring
- Webhook URL is stored securely in environment variables or config
- Logs are stored in Windows temp directory
- No sensitive system information is transmitted
Customization
Edit windows-reboot-monitor.ps1 to:
- Change Discord message format
- Add additional system information
- Modify notification colors
- Adjust logging behavior
- Add email notifications as backup
Uninstallation
# Remove scheduled tasks
schtasks /delete /tn "Discord Reboot Monitor - Startup" /f
schtasks /delete /tn "Discord Reboot Monitor - Shutdown" /f
# Remove files
Remove-Item -Path "C:\Scripts\windows-reboot-monitor.ps1" -Force
Remove-Item -Path "C:\Windows\Temp\reboot-monitor.*" -Force
# Remove environment variable
[Environment]::SetEnvironmentVariable("DISCORD_WEBHOOK_URL", $null, "Machine")