Skip to content

Instantly share code, notes, and snippets.

@goyalmohit
Created February 8, 2019 22:30
Show Gist options
  • Select an option

  • Save goyalmohit/409ac8f9716b428d0d9e2835f80232ac to your computer and use it in GitHub Desktop.

Select an option

Save goyalmohit/409ac8f9716b428d0d9e2835f80232ac to your computer and use it in GitHub Desktop.
Displays progress for nested loop operations in PowerShell 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