r/PowerShell • u/icebreaker374 • 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?
14
Upvotes
View all comments
Show parent comment
1
u/ka-splam Sep 18 '26 edited Sep 18 '26
Indeed; I needed to delete Windows firewall rule spam recently and found https://stackoverflow.com/a/40915201
The question loops over
Remove-NetFirewallRuleand says it's too slow, that answer's hot loop is:Remove-ItemPropertyGet-DateWrite-Progressthey say "The difference is one hour vs days. I could be deleting 10,000 - 100,000 firewall rules!".
I used
$key = [Microsoft.Win32.Registry]::LocalMachine.OpenSubKey(...)and then replaced the loop with just$key.DeleteValue(...)and it did 40k firewall rules in a second or two. No need for a progress count or ETA.