Repository navigation
Description
Write-Progress has long been perhaps the most neglected of the standard Write-* cmdlets. The problems with it are both in terms of its user-facing and in terms of its behind-the-scenes implementation, and I'll attempt to break them up as such.
Behind-the-Scenes Problems
- There is no
Progressstream. This makes it the only defaultWrite-*cmdlet without a matching stream (barring of course the special-casedWrite-Host, which utilises the Information stream).- I believe there should be a stream, and that stream should be handled in a similar way to the Information stream in terms of the objects that pass through it (though naturally Progress displays by default, unlike Information).
- Providing a stream for this permits suppression and redirection of the progress information from specific cmdlets instead of requiring that an implementation continually override
$ProgressPreferenceand hope that it works. - The fact that it is stream-like is more confusing for users, given that it seems to respect $ProgressPreference variable values that mimic the standard stream preferences' available levels, but it cannot be redirected and there is no common parameter for handling it as with all the other stream-type Write-* cmdlets.
- The
$ProgressPreferencevariable is not handled the same as, for example,$ErrorActionPreference, or indeed most other preference variables that work with streams; it seems to be simply a variable that theWrite-Progresscmdlet looks to see is defined and acts accordingly.- Because Progress is not a stream, the only way to attempt to handle, suppress, or indeed do anything at all with the Progress data is via this variable. This makes it incredibly unwieldy, because in order to tell a command not to show a progress bar, the variable needs to be modified both before & after the command (in order to restore it to normal order).
- Combined with this, there's no way to check if the preference is being altered by the caller of the cmdlet (i.e., as you can do with
$PSBoundParameters['ErrorAction']) or if the value is simply stored in the$ProgressPreferencevariable from... really, no one knows where, for sure.
User-Facing (Usability) Problems
See this project: https://github.com/mazzy-ax/Write-ProgressEx
Write-Progress is probably the only (that I've seen...) default Write-* cmdlet that spawned an entire project to help deal with its idiosyncrasies. Write-Information has spawned a couple, to allow easier interaction with the necessary metadata that sets display colors on those objects (but that's a separate issue), but pretty much no other default stream / associated Write- cmdlet has received or needs this much coddling from the community.
We need only look at the README.MD file on the above linked repository for a fairly comprehensive summary of the present pain-points with the default Write-Progress cmdlet that the creator felt it necessary to fix.
Write-ProgressEx extends the functionality of the standard powershell cmdlet. Write-ProgressEx is a powershell native cmdlet that provides a simple way to show ProgressBars with PercentComplete and SecondsRemaining.
The cmdlet:
- works with pipe;
- works with empty activity string;
- completes all inner progresses if no parameters;
- automatically completes with pipe;
- automatically calculates percents, remaining seconds and elapsed time;
- automatically displays current iteration and totals on progress bar;
- automatically set parent id for a inner loop;
- stores totals, current values and actual parameters into the module hashtable;
- provides get/set cmdlets to access actual parameters;
- uses script blocks to show messages with date, time, iterations and elapsed time on events:
- first iteration;
- activity changed;
- status changed;
- completed.
- provides a counter functional. See Write-ProgressEx as a counter;
- uses the caller function name or the caller script file name as the Activity;
- accepts -ShowProgressBar Auto parameter to reduce the overhead for redrawing a screen. It recognizes None and Force values also.
The sheer amount of manual calculations required to use the default Write-Progress cmdlet is pretty absurd, in my opinion. We don't need to determine for ourselves the basic functional information or metadata for any default stream-writing cmdlet, really.
There is so much manual input the user is forced to almost completely create the progress bar, and all Write-Progress is doing is working out purely the display issues. This makes some sense, but it doesn't seem to make any sense to me to make it such a difficult command to work with. The current implementation of the Write-Progress cmdlet seems more apropos for an internal utility command to support a fully-fledged Write-Progress cmdlet, and I would argue appears to have been designed as such.
And if you think it's not that important, because it doesn't get that much use -- there's a reason it doesn't see much use: it's really hard to use decently well. A related sidenote here is that it probably needs some capability to measure things otherwise opaque to the user -- for example when Copy-Item is used, it's relatively difficult to figure out how to measure the progress of copying, say, a single large file. Something would likely need to be worked out for that to be more intuitive for users.
Environment data
Written as of PS 6.1.0
Activity
SteveL-MSFT commentedon Oct 10, 2018
Rain Sallow (/u/ta11ow) (@vexx32) thanks for taking the time to write this up. I agree with what you are saying. My only concern is this is not a small work item.
vexx32 commentedon Oct 10, 2018
Well, no, of course not. 😄
It would be unrealistic to expect it all fixed at once, but I think it's well past the time where the framework for this should be in place.
It may be worth reaching out to the author of the aforementioned module and asking if they are interested in potentially translating portions of their module to be incorporated into the native Write-Progress cmdlet.
I think the most sensible overall course of action is:
ProgressRecordobject to consist of.refitems for things submitted to the stream for display?But, of course, several of those are fairly large ??? in terms of how long they would take and the finer details of their implementation.
That said, however, I think that although PowerShell's focus is automation, it is relatively important to be capable of supporting a consistent and accessible progress display. Currently, the verbose and other streams are, I would think, somewhat overburdened, because there is no other effective and simple way to really report progress on a large job.
mklement0 commentedon Oct 10, 2018
NIcely structured write-up, Rain Sallow (/u/ta11ow) (@vexx32)
Supporting
-ProgressActionas a common parameter readily makes sense to me, not least because advanced functions inside modules do not see the caller's preference variables - see #4568.Knowing little about the current
Write-Progressand how it could be improved, what is the benefit of creating a progress stream, given the ephemeral nature of progress display?Collecting the stream output wouldn't make much sense, for instance.
I'm sure I'm missing something, but perhaps you can flesh out the rationale for that, and for who would act on the stream when.
vexx32 commentedon Oct 10, 2018
My thought is essentially that having it mimic the current stream natures is a good parallel and provides more flexibility. For example, currently only one command can really display progress at a time. Providing the capability for more commands to display progress (potentially as sub-progress-bars?) at the same time permits a more verbose display if needed without excessively heavy amounts of
Write-Verbosewithin a script which leaves you with screens of yellow text that sometimes manages to be harder to make sense of than just a blinking cursor with no indication of what's going on.Granted, you may not always want all of these to display; potentially we could deviate a bit from the standard "action" parameters of ErrorActionPreference and the like for something more suitable, perhaps setting the number of 'nested command progress bars' that are displayed with the main command as a preference variable.
I am more than open to alternative ideas, and as you point out completely copying the existing stream behaviour is not likely to yield a worthwhile result, as I have previously touched upon with a few points here and there. 😄
Jaykul commentedon Nov 7, 2018
If we did not have Write-Progress -- would you consider doing any of this work to add it?
What's the purpose of the new stream? Obviously everything written to it currently is inherently ephemeral and thus, it's never used for information which needs to be logged -- in fact, logging the information would almost always result in huge logs with very little value.
I'm not inherently opposed to the idea of making progress a full-blown stream, but I feel like I should defend the current implementation a little:
Having said all that ... if we did want to log-enable progress output ...
What if we harness the information stream?
That is, rewrite Write-Progress the same way Write-Host was written:
Write-Host: creates a
HostInformationMessageto hold a few extra pieces of information (color, newlines, etc) and outputs it to the InformationStream with the tag PSHost.Write-Progress: create a
HostProgressMessageto hold a few extra pieces of information (percent, parent/child, etc), and output it to the InformationStream with the tag PSProgress.Then hook the host up to pull that out and display it the way we display it now...
vexx32 commentedon Nov 8, 2018
I think that idea is a good one. But we probably don't want to log progress records to transcript, so they'd have to be filtered out.
iSazonov commentedon Nov 8, 2018
Previously, Write-Progress slowed down scripts and we made a lot of effort to fix this. There are a few more problems. See the tracking Issue #3366.
Because of allocation problem I'm sure it should not be a stream.
And we could consider async methods to resolve some problems with many runspaces and locks.
And take in account a new remoting batching #8038
It is not clear for me how we'll process background jobs.
Omio commentedon Nov 29, 2018
Maybe have Write-Progress become a sub-task of the host task performing an operation, and have Write-Progress use local-scope variables from the host task to output window-only messages, that don't output to event logging, bar for the standard messages that the host task would normally output (if any)?
felixfbecker commentedon Feb 28, 2019
Forgive me if it has been mentioned before, but
Write-Progressis also freaking slow if the script outputs anything. I have a script that runs through a long loop and on every iteration logs a warning and updates the progress, runs 20s if run with either of warning or progress enabled, but takes 1h 5min 43s if run with both warning and progress on!iSazonov commentedon Mar 1, 2019
Felix Becker (@felixfbecker) If you see the problem in latest PowerShell Core please new Issue and link to #3366.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 23, 2023
This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.