Clear screen when doing a continuous performance counter

This topic contains 4 replies, has 4 voices, and was last updated by Profile photo of Windows LiveUser144 Windows LiveUser144 8 months, 3 weeks ago.

  • Author
    Posts
  • #36570
    Profile photo of Windows LiveUser144
    Windows LiveUser144
    Participant

    I am trying to get continuous disk IOPS on a server, but trying to forego the results from continuing to scroll down the screen. Instead, I'd like to clear the screen between samples to gather, and if possible do the same in an out-gridview view as well.

    $c="\PHysicalDisk(*)\Disk Reads/sec"
    get-counter -counter $c -computername server1 -continuous -sampleinterval 5

  • #36571
    Profile photo of Thom Schumacher
    Thom Schumacher
    Participant

    you could use this endless loop that was provided here: http://powershell.com/cs/blogs/tips/archive/2016/03/11/cleverly-aborting-endless-loop.aspx

    Then make a script similar to this:

     
    $c="\PHysicalDisk(*)\Disk Reads/sec"
    $displaycount = 20
    try
    {
        do
        {
            $i+=$i
            $counter = get-counter -counter $c -sampleinterval 5
            if($i -eq $displaycount)
            {
                cls
                $i = 0
            }
            write-output $counter
        }while($true)
    }
    catch
    {
      $sapi = New-Object -ComObject Sapi.SpVoice
      $sapi.Speak('Hey, you aborted me dammit!')
    }
    
  • #36573
    Profile photo of Christian Sandfeld
    Christian Sandfeld
    Participant

    This will not work with Out-Gridview, but you could "refresh" you console window with this

    $ComputerName = 'server1'
    $Counter = '\PHysicalDisk(*)\Disk Reads/sec' 
    $SampleInterval = 5
    
    Get-Counter -Counter $Counter -ComputerName $ComputerName -SampleInterval $SampleInterval -Continuous | ForEach-Object {
        Clear-Host
        $_
    }
    
  • #36574
    Profile photo of Bob McCoy
    Bob McCoy
    Participant

    There is no inherent way within that cmdet.

    while ($true) { cls; get-counter -counter $c -computername util1; sleep 5 }

    EDIT: Oops. Essentially the same as above. He was just quicker.

  • #36582
    Profile photo of Windows LiveUser144
    Windows LiveUser144
    Participant

    Thanks all for your quick responses. I love this community and how much we are all willing to help each other out. I've tried Christian's solution and it looks like it will work for me.

You must be logged in to reply to this topic.