← script library

Quickly Check System Resource Utilization with PowerShell

Monitoring & HealthDecember 24, 2024

In this post, we will present a PowerShell script that allows you to quickly check the system resource utilization on your Windows machine. Monitoring CPU, memory, and disk usage is critical for maintaining optimal performance and identifying potential issues before they escalate. This script gathers and displays the current resource utilization stats in an easy-to-read format, helping you keep your systems healthy. Here is the PowerShell script for checking system resource utilization:

powershell
# Get CPU usage
$cpuUsage = Get-WmiObject Win32_Processor | Measure-Object -Property LoadPercentage -Average
$avgCpuLoad = $cpuUsage.Average
# Get Memory usage
$memory = Get-WmiObject Win32_OperatingSystem
$totalMemory = $memory.TotalVisibleMemorySize / 1MB
$freeMemory = $memory.FreePhysicalMemory / 1MB
$usedMemory = $totalMemory - $freeMemory
# Get Disk usage
$disks = Get-PSDrive -PSProvider FileSystem
# Display results
Write-Host "CPU Load: $avgCpuLoad%"
Write-Host "Total Memory: $([math]::round($totalMemory, 2)) MB"
Write-Host "Used Memory: $([math]::round($usedMemory, 2)) MB"
Write-Host "Free Memory: $([math]::round($freeMemory, 2)) MB"
foreach ($disk in $disks) {
    $used = [math]::round($disk.Used / 1GB, 2)
    $free = [math]::round($disk.Free / 1GB, 2)
    $total = [math]::round($disk.Used / 1GB + $disk.Free / 1GB, 2)
    Write-Host "$($disk.Name): Used $used GB, Free $free GB, Total $total GB"
}

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.