Scripting Technique

Adding a status Bar to Functions and Scripts in PowerShell.

Write-Progress Anyone?

greetings tourist,

Welcome to PowerShell City! My name is Xajuan Smith.

My first post is about progress, The “Write-Progress” cmd-let  that is….

I have not seen a lot of people use the progress bar for anything, But I feel obligated to suggest using this for long running scripts and other advanced multi-faceted projects that need to report it’s progress.

So lets start some tests with a total number :



$total= gc file.txt ; $total.count


$objects= import-csv c:\some.csv

$total= $objects.count

#this will count the lines or objects if you prefer that

lets create a variable to start the count at 0 before we do a foreach loop. and add the rest of the information below:

write-host “”   #writing a blank

write-host “Time Script Started : $(get-date)” -ForegroundColor Green
foreach ($Object in $Objects)


write-progress -Activity “Copying $object.source to $ ” -PercentComplete ($count/$total*100.00) -Status “$($total – $count) Remaining to be Copied”


This will help hopefully unravel the mystery of the Cmdlet write-progress!

return to the City when you have time see you next visit!


if you are doing a loop in a loop you can write progress for the internal loop by marking using the “-parentID”, “-Completed” and “-Id” parameter

thanks for visiting the City.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.