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
#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 $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!
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.