Created
October 11, 2018 19:47
-
-
Save poshcodebear/e0021fbcfe5ea06fa6b7af1459732dc3 to your computer and use it in GitHub Desktop.
Demonstration of PowerShell's Write-Progress cmdlet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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