How do you hide a Powershell progress message?

2019-02-12 09:48发布

问题:

I think Write-Progress is a rather beautiful Cmdlet. In fact Sharepoint makes use of it with its Start-SPAdminJob commandlet.

All fine and dandy, the problem is that Start-SPAdminJob does not correctly "dispose" of the Write-Progress dialog. It is never set to 100 percent complete which means it just stays in the Powershell dialog until you exit the script - this in turn hides part of the messages underneath the "progress window".

Is there any way I can force an existing Write-Progress to "exit" or be set to 100% complete? Any way how I could find out the ID of the progress the Start-SPAdminJob cmdlet is using - that way I could manually set the percentage.

回答1:

You could stop the progress bar appearing in the first place by doing the following beforehand:

$ProgressPreference = "SilentlyContinue";

You could then restore the preference to "Continue" afterwards. Not much help if you actually want the bar of course...



回答2:

This code forces progress bar to be set to 100% complete and hides it:

Write-Progress "Done" "Done" -completed