PoshCode Archive  Artifact [85aed9462d]

Artifact 85aed9462d8491ed9fbdaffe1b5225142710edaf00d19cfae9f189375e59fd74:

  • File Get-ProcessorGraph.ps1 — part of check-in [bd961cb63f] at 2018-06-10 13:44:43 on branch trunk — Shows CPU utilization till $host height size (user: greg zakharov size: 978)

# encoding: ascii
# api: powershell
# title: Get-ProcessorGraph
# description: Shows CPU utilization till $host height size
# version: 0.1
# type: function
# author: greg zakharov
# license: CC0
# function: Get-ProcessorGraph
# x-poshcode-id: 4693
# x-archived: 2013-12-14T07:27:23
# x-published: 2013-12-12T13:38:00
#
#
#function Get-ProcessorGraph {
  begin {
    $pc = New-Object Diagnostics.PerformanceCounter("Processor", "% Processor Time", "_Total")
    $raw = $host.UI.RawUI
    
    function strip([Int32]$x, [Int32]$y, [Int32]$z, [ConsoleColor]$bc) {
      $pos = $raw.WindowPosition;$pos.X += $x;$pos.Y += $y
      $row = $raw.NewBufferCellArray(@(' ' * $z), $bc, $bc)
      $raw.SetBufferContents($pos, $row)
    }
  }
  process {
    for ($i = 0; $i -lt $raw.WindowSize.Height; $i++) {
      strip 0 $i ([Math]::Round(($pc.NextValue() * 100 / $raw.WindowSize.Width + 1))) 'Green'
      sleep -s 1
    }
  }
  end {
    cls
  }
#}