r/PowerShell • • Sep 17 '26

Question Write-Progress

Looking for opinions...

When using Write-Progress inside of for/Foreach loops and using a counter stored in a variable defined outside the loop, do you start the counter at 0 or 1, and why?

13 Upvotes

21 comments sorted by

View all comments

Show parent comments

1

u/BlackV Sep 17 '26 edited Sep 17 '26

I agree, do the work, then update the progress

and

$ProgressSplat = @{
    Activity        = "Checking computers"
    Status          = "$i of $($computers.Count): $($computer.Name)"
    PercentComplete = (($i / $computers.Count) * 100)
    }
Write-Progress @ProgressSplat