Keeping your systems healthy and performance-optimized is crucial for ensuring that your IT environment runs smoothly. Regular system health checks help identify issues before they become critical problems. This PowerShell script automates health checks for Windows servers, providing a summary of vital system metrics including CPU usage, memory usage, disk space, and service status. This script will: 1. Check CPU and memory usage. 2. Report available disk space on all drives. 3. Verify the status of essential services. Running this script on a scheduled basis can help maintain your infrastructure's health.
# Get CPU Usage
$cpuUsage = Get-Counter '\Processor(_Total)\% Processor Time'
$cpuLoad = $cpuUsage.Counters[0].CookedValue
# Get Memory Usage
$memInfo = Get-WmiObject Win32_OperatingSystem
$memAvailableGB = [math]::round(($memInfo.FreePhysicalMemory / 1MB), 2)
$memTotalGB = [math]::round(($memInfo.TotalVisibleMemorySize / 1MB), 2)
$memUsagePercent = [math]::round(($memTotalGB - $memAvailableGB) / $memTotalGB * 100, 2)
# Get Disk Space
$diskInfo = Get-PSDrive -PSProvider FileSystem
# Get Service Status (Example service - set your critical services here)
$criticalServices = @('wuauserv', 'bits', 'eventlog')
$serviceStatus = @{}
foreach ($service in $criticalServices) {
$serviceStatus[$service] = (Get-Service -Name $service).Status
}
# Output Results
Write-Host "=== System Health Check Results ==="
Write-Host "CPU Load: $cpuLoad %"
Write-Host "Memory Usage: $memUsagePercent % (Available: $memAvailableGB GB, Total: $memTotalGB GB)"
Write-Host "Disk Space:"
foreach ($disk in $diskInfo) {
Write-Host "$($disk.Name): $([math]::round($disk.Used / 1GB, 2)) GB used, $([math]::round($disk.Free / 1GB, 2)) GB free"
}
Write-Host "Service Status:"
foreach ($service in $criticalServices) {
Write-Host "$service: $($serviceStatus[$service])"
}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.