简体   繁体   English

在PowerShell 3.0中自动刷新Out-GridView

[英]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. 我试图让PowerShell(v3.0)创建的GridView定时自动刷新。 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? 如何让这个表单自动刷新60秒? 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不支持自动刷新。 Out-GridView takes the result from Get-Process (which in this code is only called once) and displays it in a gridview. Out-GridViewGet-Process结果(在此代码中仅调用一次)并将其显示在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. 要获得自动刷新,您需要在计时器上使用自定义更新逻辑创建自己的自定义表单,或者创建一个关闭gridview并在x秒后重新打开它的循环。 Like this: 像这样:

test.ps1 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). 请注意,每次刷新时,gridview都会将焦点放在屏幕上(显示在顶部)。

To get all the features you want, you need to create your own form. 要获得所需的所有功能,您需要创建自己的表单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM