Skip to content

Instantly share code, notes, and snippets.

@goyalmohit
Created February 8, 2019 22:32
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 goyalmohit/adceacf24dcee62b16a9da3c291e78a3 to your computer and use it in GitHub Desktop.
Save goyalmohit/adceacf24dcee62b16a9da3c291e78a3 to your computer and use it in GitHub Desktop.
Display progress of long running operations using Write-Progress Cmdlet
$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