我正在尝试在PowerShell生成的GUI中创建一个进度条,该GUI将显示搜索的进度,因为系统缓存了AD中的所有组(大约有12,000个,所以这只会导致系统暂停同时)
我设法建立了条形图等,但是当系统添加组时我无法填充它。以下是我到目前为止的情况:
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
$Form = New-Object System.Windows.Forms.Form
$Form.width = 345
$Form.height = 345
$Form.StartPosition = "CenterScreen"
$Form.ShowInTaskbar = $True
$Form.FormBorderStyle = 'FixedToolWindow'
$ExitButt = new-object System.Windows.Forms.Button
$ExitButt.Location = new-object System.Drawing.Size(235,5)
$ExitButt.Size = new-object System.Drawing.Size(100,20)
$ExitButt.Text = "Exit"
$Form.Controls.Add($ExitButt)
$ExitButt.Add_Click({$Form.Close()})
$Prog = New-Object System.Windows.Forms.ProgressBar
$Prog.Maximum = 10000
$Prog.Minimum = 0
$Prog.Location = new-object System.Drawing.Size(50,50)
$Prog.size = new-object System.Drawing.Size(100,50)
$Form.Controls.Add($Prog)
$Button = new-object System.Windows.Forms.Button
$Button.Location = new-object System.Drawing.Size(120,100)
$Button.Size = new-object System.Drawing.Size(100,30)
$Button.Text = "Start Progress"
$Form.Controls.Add($Button)
$Button.add_click(
{
$GroupsList = Get-ADGroup -Server "server" -Filter *
$Count = ($GroupsList | Measure-Object).Count
$prog.Value = $Count
}
)
$form.ShowDialog() | Out-Null
答案 0 :(得分:0)
要更新WinForms ProgressBar
,只需设置其Value
属性。
例如
# Initialisation...
$myProgBar.Minimum = 1;
$myProgBar.Maximum = 100;
# When something happens...
$myProgBar.Value = 50;
将它设置为中途。