Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you hide a Powershell progress message?

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.

like image 988
Dennis G Avatar asked Jul 11 '11 13:07

Dennis G


2 Answers

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...

like image 87
MrKWatkins Avatar answered Oct 17 '22 06:10

MrKWatkins


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

Write-Progress "Done" "Done" -completed
like image 44
Alexey A. Avatar answered Oct 17 '22 05:10

Alexey A.