Create a gist now

Instantly share code, notes, and snippets.

@voidproc /cpu.ps1 Secret
Created Jan 28, 2017

What would you like to do?
$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