I made a version of @Scepticalist code to run through a list of functions and show the progress of their total execution:
Add-Type -AssemblyName System.Windows.Forms
# These 3 functions will be called in sequence
function Function1 {
param ($param1, $param2)
Write-Host "Executing Function 1 with parameters: $param1 and $param2"
Start-Sleep -Seconds 1
}
function Function2 {
param ($msg)
Write-Host "Executing Function 2 with argument: $msg"
Start-Sleep -Seconds 1
}
function Function3 {
param ($msg)
Write-Host "Executing Function 3 with argument: $msg"
Start-Sleep -Seconds 1
}
# Array with the names of the functions that will be called
$functions = @("Function1", "Function2", "Function3")
$totalFunctions = $functions.Count
$form = New-Object System.Windows.Forms.Form
$form.Text = "Processing"
$form.Size = New-Object System.Drawing.Size(400, 200)
$form.FormBorderStyle = 'Fixed3D'
$form.ControlBox = $false
$form.StartPosition = "CenterScreen"
$ProgressBar = New-Object System.Windows.Forms.ProgressBar
$ProgressBar.Minimum = 0
$ProgressBar.Maximum = $totalFunctions
$ProgressBar.Location = New-Object System.Drawing.Size(10, 80)
$ProgressBar.Size = New-Object System.Drawing.Size(300, 20)
$form.Controls.Add($ProgressBar)
$form.Show()
# Call each function and update the progress bar
for ($i = 0; $i -lt $totalFunctions; $i++) {
& $functions[$i] "FirstParameter" "SecondParameter"
$ProgressBar.Value = $i + 1
}
$form.Dispose()