← script library
Automated Windows Service Monitoring with PowerShell
Monitoring & HealthDecember 24, 2024
In this post, we will share a PowerShell script that automates the monitoring of Windows services on your system. Keeping track of service statuses is essential to ensure that critical applications are running smoothly. This script provides an easy way to check the status of specified services and can notify administrators if any services are stopped, enabling quick responses to potential issues. Here is the PowerShell script for monitoring Windows services:
powershell
# Define the list of services to monitor
$servicesToMonitor = @("Spooler", "wuauserv", "MSSQLSERVER")
# Check the status of each service
foreach ($service in $servicesToMonitor) {
$serviceStatus = Get-Service -Name $service
# Display the status
Write-Host "Service: $($serviceStatus.Name) - Status: $($serviceStatus.Status)"
# Check if the service is stopped
if ($serviceStatus.Status -eq 'Stopped') {
Write-Host "Warning: The service '$service' is stopped. Attempting to start..."
Start-Service -Name $service
Write-Host "Service '$service' has been started."
}
}Run it across your fleet
This script runs as-is on a single host. Paste it into ServerEngine to schedule it, run it on a whole server group in parallel, and keep the credentials out of the file — see the scripts documentation and the credential store.
More in Monitoring & Health
Disk Space Cleanup and Report Script
2025-01-14User Account Status Reporting Script
2025-01-13Automated Disk Space Monitoring Script
2025-01-13Monitor System Performance with PowerShell
2025-01-12Automating System Health Check with PowerShell
2025-01-05Automate System Performance Monitoring with PowerShell
2024-12-30Ready when you are.
Try ServerEngine free for 7 days.