Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Write-Progress

$
0
0

Trying to understand the Write-Progress cmdlet. From my understanding, it is to give an indicatin of how long the script will run, but in reality that is not the case. For instance from the following Scripting Guys Article, he has the following example:

$files = Get-ChildItem -Path c:\fso
For($i = 1; $i -le $files.count; $i++)
{ Write-Progress -Activity "Collecting files" -status "Finding file $i" -percentComplete ($i / $files.count*100)}
$files | Select name

This would not give a real time indication of progress, as Get-ChildItem needs to finish before you reach the for loop, then all you are really doing is looping through the collection of files and counting.

So how would you use Write-Progress to give you a more realistic measure of progress, and also, how do you know in which part of the script to actually, put the code for the Write-Progress?


If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful.

Don't Retire Technet


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>