Clear screen when doing a continuous performance counter

Welcome Forums General PowerShell Q&A Clear screen when doing a continuous performance counter

This topic contains 4 replies, has 4 voices, and was last updated by

 
Participant
2 years, 8 months ago.

  • Author
    Posts
  • #36570

    Participant
    Points: 0
    Rank: Member

    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

    Participant
    Points: 42
    Rank: Member

    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

    Participant
    Points: 14
    Rank: Member

    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

    Participant
    Points: 0
    Rank: Member

    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

    Participant
    Points: 0
    Rank: Member

    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.

The topic ‘Clear screen when doing a continuous performance counter’ is closed to new replies.