Skip to content

Instantly share code, notes, and snippets.

@voidproc

voidproc/cpu.ps1 Secret

Created January 28, 2017 12:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save voidproc/b18266598a3312145d33c9b43d61f9cf to your computer and use it in GitHub Desktop.
Save voidproc/b18266598a3312145d33c9b43d61f9cf to your computer and use it in GitHub Desktop.
$rui = $Host.UI.RawUI
$pos = New-Object System.Management.Automation.Host.Coordinates 0,($rui.CursorPosition.Y - 1)
# Drop ghost 'Enter' keyup
$rui.ReadKey("NoEcho,IncludeKeyUp") >$null
while ($true)
{
$cputime = ((Get-WmiObject Win32_PerfFormattedData_PerfOS_Processor).PercentProcessorTime)[0]
$rui.CursorPosition = $pos
Write-Host "${cputime}% ".PadLeft(5) -ForegroundColor Green -NoNewline
Write-Host ("`#" * [Math]::Truncate($cputime[0] * 20 / 100)).PadRight(20) -ForegroundColor Green -BackgroundColor Black -NoNewline
1..10 | ForEach-Object {
if ($rui.KeyAvailable)
{
$vk = $rui.Readkey("NoEcho,IncludeKeyUp,IncludeKeyDown").VirtualKeyCode
if ($vk -ne 16 -and $vk -ne 17 -and $vk -ne 18) { break } # modifiers
}
Start-Sleep -Milliseconds (1000/10)
}
}
$rui.CursorPosition = $pos
Write-Host (" " * $rui.WindowSize.Width) -NoNewline
$rui.CursorPosition = $pos
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment