Simple System Health Monitor
# Simple System Health Monitor
function Show-Menu {
Clear-Host
Write-Host "=== Simple System Health Monitor ===" -ForegroundColor Cyan
Write-Host "1. Check CPU Usage"
Write-Host "2. Check Memory Usage"
Write-Host "3. Check Disk Space"
Write-Host "4. List Top 5 CPU-Consuming Processes"
Write-Host "5. Check System Uptime"
Write-Host "6. Exit"
}
function Check-CPUUsage {
$cpu = Get-WmiObject Win32_Processor | Measure-Object -Property LoadPercentage -Average | Select-Object Average
Write-Host "`nCurrent CPU Usage: $($cpu.Average)%" -ForegroundColor Yellow
}
function Check-MemoryUsage {
$os = Get-Ciminstance Win32_OperatingSystem
$totalMemory = [math]::Round($os.TotalVisibleMemorySize / 1MB, 2)
$freeMemory = [math]::Round($os.FreePhysicalMemory / 1MB, 2)
$usedMemory = $totalMemory - $freeMemory
$percentUsed = [math]::Round(($usedMemory / $totalMemory) * 100, 2)
Write-Host "`nMemory Usage:" -ForegroundColor Yellow
Write-Host "Total Memory: $totalMemory GB"
Write-Host "Used Memory: $usedMemory GB"
Write-Host "Free Memory: $freeMemory GB"
Write-Host "Percent Used: $percentUsed%"
}
function Check-DiskSpace {
$disks = Get-WmiObject Win32_LogicalDisk | Where-Object {$_.DriveType -eq 3}
Write-Host "`nDisk Space:" -ForegroundColor Yellow
foreach ($disk in $disks) {
$freeSpace = [math]::Round($disk.FreeSpace / 1GB, 2)
$totalSpace = [math]::Round($disk.Size / 1GB, 2)
$usedSpace = $totalSpace - $freeSpace
$percentFree = [math]::Round(($freeSpace / $totalSpace) * 100, 2)
Write-Host "Drive $($disk.DeviceID):"
Write-Host " Total: $totalSpace GB"
Write-Host " Used: $usedSpace GB"
Write-Host " Free: $freeSpace GB"
Write-Host " Percent Free: $percentFree%"
Write-Host ""
}
}
function Get-TopCPUProcesses {
Write-Host "`nTop 5 CPU-Consuming Processes:" -ForegroundColor Yellow
Get-Process | Sort-Object CPU -Descending | Select-Object -First 5 |
Format-Table Name, @{Name='CPU (s)'; Expression={$_.CPU.ToString('N2')}}, @{Name='Memory (MB)'; Expression={[math]::Round($_.WorkingSet / 1MB, 2)}} -AutoSize
}
function Check-Uptime {
$uptime = (Get-Date) - (Get-CimInstance Win32_OperatingSystem).LastBootUpTime
Write-Host "`nSystem Uptime: $($uptime.Days) days, $($uptime.Hours) hours, $($uptime.Minutes) minutes" -ForegroundColor Yellow
}
do {
Show-Menu
$choice = Read-Host "`nEnter your choice (1-6)"
switch ($choice) {
"1" { Check-CPUUsage }
"2" { Check-MemoryUsage }
"3" { Check-DiskSpace }
"4" { Get-TopCPUProcesses }
"5" { Check-Uptime }
"6" { Write-Host "Exiting program..." -ForegroundColor Yellow; break }
default { Write-Host "Invalid choice. Please try again." -ForegroundColor Red }
}
if ($choice -ne "6") {
Read-Host "`nPress Enter to continue..."
}
} while ($choice -ne "6")
This System Health Monitor includes:
- A menu with 6 options
- Functions for various system health checks:
- Checking CPU usage
- Checking memory usage
- Checking disk space
- Listing top CPU-consuming processes
- Checking system uptime
- Use of PowerShell cmdlets like
Get-WmiObject,Get-CimInstance, andGet-Process - Basic calculations for memory and disk usage percentages
- Formatted output for better readability
This tool provides a quick overview of essential system health metrics. It’s useful for:
- Monitoring system performance
- Identifying potential resource bottlenecks
- Checking available disk space
- Identifying processes that are consuming high CPU
- Determining how long the system has been running
This script is suitable for users who want to perform basic system health checks without needing to navigate through multiple system tools or commands. It provides a simple interface for accessing important system information quickly and easily.

Leave a Reply
Want to join the discussion?Feel free to contribute!