Partilhar via


Easy progress bar in your Powershell scripts…

Ever wondered how far a long running Powershell script has come?

I use this piece of code in pretty much all my scripts to keep track, very useful if you process large amounts of data:

    1: $i = 1
    2:  
    3: foreach ($item in $collection) {
    4:  
    5:     $pct = (($i / $collection.count)*100)
    6:     Write-Progress -activity "Processing..." -status "Progress: $([int]$pct)%" -PercentComplete $pct
    7:     
    8:     # processing stuff goes here
    9:  
   10:     $i++
   11: }

Feel free to use it wherever you want… :)