← script library

Perform System Health Checks Using PowerShell

Monitoring & HealthDecember 24, 2024

In this post, we will provide a PowerShell script designed to perform system health checks on Windows servers. Regular health checks are crucial to ensure that your servers are running optimally and to identify potential issues before they escalate. This script will check CPU usage, memory usage, and disk space, providing a concise report of the system's status. By maintaining system health, you can enhance reliability and performance within your IT environment. Here is the PowerShell script to perform the health checks:

powershell
# Check CPU usage
$cpuUsage = Get-WmiObject -Class Win32_Processor | Measure-Object -Property LoadPercentage -Average
$cpuLoad = $cpuUsage.Average
# Check Memory usage
$mem = Get-WmiObject -Class Win32_OperatingSystem
$memUsage = [math]::round(($mem.TotalVisibleMemorySize - $mem.FreePhysicalMemory) / 1MB, 2)
# Check Disk space
$diskSpace = Get-PSDrive -PSProvider FileSystem | Select-Object Name, @{Name='Used(GB)';Expression={[math]::round($_.Used/1GB,2)}}, @{Name='Free(GB)';Expression={[math]::round($_.Free/1GB,2)}}, @{Name='Total(GB)';Expression={[math]::round($_.Used/1GB + $_.Free/1GB,2)}}
# Output report
Write-Host "CPU Load: $cpuLoad%"
Write-Host "Memory Usage: $memUsage MB"
$diskSpace | Format-Table -AutoSize
Write-Host "System health check completed."

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.

Ready when you are.

Try ServerEngine free for 7 days.