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?
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.