Perform System Health Checks Using PowerShell
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:
# 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."