Created
February 8, 2019 22:32
-
-
Save goyalmohit/adceacf24dcee62b16a9da3c291e78a3 to your computer and use it in GitHub Desktop.
Display progress of long running operations using Write-Progress Cmdlet
This file contains hidden or 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
$outerLoopMax = 255 | |
$innerLoopMax = 126 | |
for ($outerCounter=1; $outerCounter -lt $outerLoopMax; $outerCounter++) { | |
Write-Progress -Activity "Main loop progress:" ` | |
-PercentComplete ([int](100 * $outerCounter / $outerLoopMax)) ` | |
-CurrentOperation ("Completed {0}%" -f ([int](100 * $outerCounter / $outerLoopMax))) ` | |
-Status ("Outer loop working on item [{0}]" -f $outerCounter) ` | |
-Id 1 | |
Start-Sleep -Milliseconds 100 | |
for ($innerCounter=1; $innerCounter -lt $innerLoopMax; $innerCounter++) { | |
Write-Progress -Activity "Inner loop progress:" ` | |
-PercentComplete ([int](100 * $innerCounter / $innerLoopMax)) ` | |
-CurrentOperation ("Completed {0}%" -f ([int](100 * $innerCounter / $innerLoopMax))) ` | |
-Status ("Inner loop working on item [{0}]" -f $innerCounter) ` | |
-Id 2 ` | |
-ParentId 1 | |
Start-Sleep -Milliseconds 10 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment