Skip to content

Instantly share code, notes, and snippets.

@rossarioking
Created September 23, 2023 14:13
Show Gist options
  • Save rossarioking/03e8d6bffebd3ad6e692d75182f180b6 to your computer and use it in GitHub Desktop.
Save rossarioking/03e8d6bffebd3ad6e692d75182f180b6 to your computer and use it in GitHub Desktop.
Powershell Script to Monitor CPU of Remote Host
$computerName = "RemoteComputerName" # Replace with the name or IP address of the remote computer
$counterPath = "\\$computerName\Processor(_Total)\% Processor Time"
# Continuous monitoring loop
while ($true) {
$cpuUsage = (Get-Counter -Counter $counterPath).CounterSamples.CookedValue
Write-Host "CPU Usage on $computerName: $($cpuUsage)%" -ForegroundColor Green
Start-Sleep -Seconds 5 # Adjust the sleep interval as needed
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment