Trying to learn how to build progress bars, I looked over a few examples and tried to build one to add to my GUI. Right now I just want to get it to loop through and increase to 98% then fall back down to a random spot. Using pieces from another post Powershell Progress Bar in Windows Forms I tried to put a loop in, its not working though.
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
$form_main = New-Object System.Windows.Forms.Form
$form_main.Width = 300
$form_main.Height = 100
$form_main.Text = 'ProgressBar demo'
$progressBar1 = New-Object System.Windows.Forms.ProgressBar
$progressBar1.Location = new-object System.Drawing.Size(10,10)
$progressBar1.Size = new-object System.Drawing.Size(265,20)
$form_main.Controls.Add($progressBar1)
$Counter = 0
$progressBar1.Value = $Counter
$progressBar1.Step = 1
$progressBar1.Name = 'progressBar1'
$progressBar1.Maximum = 100
$Num = Get-Random -Minimum 50 -Maximum 90
While ($Counter -lt 100) {
$progressBar1.PerformStep()
}
if ($Counter -gt 98) {$Counter = $Counter -= $Num}
$form_main.ShowDialog() | Out-Null
Let me know where I am going wrong.