Skip to content

Instantly share code, notes, and snippets.

@poshcodebear
Created October 11, 2018 19:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save poshcodebear/e0021fbcfe5ea06fa6b7af1459732dc3 to your computer and use it in GitHub Desktop.
Save poshcodebear/e0021fbcfe5ea06fa6b7af1459732dc3 to your computer and use it in GitHub Desktop.
Demonstration of PowerShell's Write-Progress cmdlet
$first = 'One', 'Two', 'Three'
$second = 'A', 'B', 'C'
$counter1 = 0
foreach ($number in $first) {
$progress = @{
Activity = "Pass $($number)"
Status = 'Starting'
Id = 1
PercentComplete = ($counter1 / $first.Count) * 100
SecondsRemaining = ($first.Count - $counter1) * ($second.Count * 4 + 3)
}
Write-Progress @progress
Start-Sleep -Seconds 3
$counter2 = 0
foreach ($letter in $second) {
$progress.Activity = "Item $($letter)"
$progress.Status = 'Processing...'
$progress.CurrentOperation = "Running process"
$progress.PercentComplete = ($counter2 / $second.Count) * 100
$progress.SecondsRemaining = ($second.Count - $counter2) * 4
$progress.Id = 2
$progress.ParentId = 1
Write-Progress @progress
Start-Sleep -Seconds 3
Write-Progress @progress -Completed
Start-Sleep -Seconds 1
$counter2++
}
$counter1++
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment