文本参数不适用于 Powershell 进度条

Text parameter not working with Powershell Progress Bar

过去半小时我一直在寻找如何在 Powershell 中的 GUI ProgressBar 中显示文本,但我尝试的一切都失败了。我什至一直在参考 MSoft 文档。

我是不是做错了什么?如何在文本中添加?

这不是我的完整脚本,也不是我将如何使用它 - 我只是做了一个例子,所以我可以尝试让它工作。

Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$form = New-Object System.Windows.Forms.Form
$form.Size = '500,300'
$form.StartPosition = 'CenterScreen'
$form.Topmost = $true

$computerList = 'server01', 'server02', 'server03', 'server04', 'server05', 'server06', 'server07', 'server08', 'server09', 'server10'

$progressbar1 = New-Object System.Windows.Forms.ProgressBar
$progressbar1.Size = '300, 20'
$progressbar1.Location = '20,60'
$progressbar1.Text = "Processing..."
$progressbar1.Maximum = $computerList.Count
$progressbar1.Step = 1
$progressbar1.Value = 0

foreach ($computer in $computerList){    
    $progressbar1.PerformStep()
}

$form.Controls.Add($progressbar1)
$form.ShowDialog()

我想最简单的方法是在进度条上方添加一个 Label 控件并更新其中的文本:

$progressLabel = New-Object System.Windows.Forms.Label
$progressLabel.Size = '300, 20'
$progressLabel.Location = '20,40'
$progressLabel.Text = "Processing..."
$form.Controls.Add($progressLabel)

foreach ($computer in $computerList){  
    $progressLabel.Text = "Doing stuff on computer '$computer'.."  
    $progressbar1.PerformStep()
    # perform your action on $computer here
}