bigmac
bigmac

Reputation: 2553

Auto Refresh Out-GridView in PowerShell 3.0

I am trying to have the GridView that is created by PowerShell (v3.0) auto refresh on a timed basis. Let take the following simple example:

Get-Process | Out-GridView

This displays a nice pretty form of all my running processes. How can I get this form to automatically refresh ever 60 seconds? As a bonus, can the form refresh and keep the previously selected sort column/order?

Upvotes: 1

Views: 8927

Answers (1)

Frode F.
Frode F.

Reputation: 54881

Auto-refresh isn't supported by Out-GridView. Out-GridView takes the result from Get-Process(which in this code is only called once) and displays it in a gridview.

To get auto-refresh, you need to create your own custom form with custom update logic on a timer, or make a loop that closes the gridview and reopens it after x seconds. Like this:

test.ps1

param(
[int]$waitseconds = 60
)

while($true) {
    Start-Process -FilePath powershell.exe -ArgumentList "-WindowStyle Hidden -Command &{ Get-Process | out-gridview; sleep $waitseconds; exit }" -Wait
}

Usage:

test.ps1

or

test2.ps1 -waitseconds 5

Be aware that each time it refreshed the gridview will take focus on screen(appear on top).

To get all the features you want, you need to create your own form.

Upvotes: 3

Related Questions