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=2000
or
$total= gc file.txt ; $total.count
or
$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:
$count=0
write-host “” #writing a blankwrite-host “Time Script Started : $(get-date)” -ForegroundColor Green
foreach ($Object in $Objects){
$count+=1
write-progress -Activity “Copying $object.source to $object.target ” -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!
also,
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.