你如何隐藏Powershell进度消息?

时间:2021-11-05 09:51:12

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

我认为Write-Progress是一个相当漂亮的Cmdlet。事实上,Sharepoint使用它的Start-SPAdminJob命令行开关。

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

所有罚款和花花公子,问题是Start-SPAdminJob没有正确“处理”写入进度对话框。它永远不会设置为100%完成,这意味着它只会停留在Powershell对话框中,直到您退出脚本 - 这反过来会隐藏“进度窗口”下面的部分消息。

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.

有什么方法可以强制现有的Write-Progress“退出”或设置为100%完成?无论如何我都能找到Start-SPAdminJob cmdlet正在使用的进度ID - 这样我就可以手动设置百分比。

2 个解决方案

#1


16  

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


4  

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

此代码强制进度条设置为100%完成并隐藏它:

Write-Progress "Done" "Done" -completed

#1


16  

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


4  

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

此代码强制进度条设置为100%完成并隐藏它:

Write-Progress "Done" "Done" -completed