如何隐藏Invoke-WebRequest的进度显示?我做了很多连续的请求,并且有我自己使用的Write-Progress显示器,所以我不需要每次都在它下面弹出内置的一个。
我使用从Invoke-WebRequest的结果自动创建的mshtml结果( IE对象),因此我不能切换到WebClient或类似的东西,除非有人提供如何从WebClient请求中获取mshtml对象的说明。
发布于 2013-09-13 01:35:12
使用$progressPreference变量。默认情况下,它的值应该是'Continue‘,除非您在其他地方对其进行了编辑,这会告诉Powershell显示进度条。由于您提到您有自己的自定义进度显示,因此我将在执行cmdlet后立即重置它。例如:
$ProgressPreference = 'SilentlyContinue' # Subsequent calls do not display UI.
Invoke-WebRequest ...
$ProgressPreference = 'Continue' # Subsequent calls do display UI.
Write-Progress ...有关偏好变量的更多信息,请访问about_preference_variables。下面是$ProgressPreference的条目:
$ProgressPreference
-------------------
Determines how Windows PowerShell responds to progress updates
generated by a script, cmdlet or provider, such as the progress bars
generated by the Write-Progress cmdlet. The Write-Progress cmdlet
creates progress bars that depict the status of a command.
Valid values:
Stop: Does not display the progress bar. Instead,
it displays an error message and stops executing.
Inquire: Does not display the progress bar. Prompts
for permission to continue. If you reply
with Y or A, it displays the progress bar.
Continue: Displays the progress bar and continues with
(Default) execution.
SilentlyContinue: Executes the command, but does not display
the progress bar.https://stackoverflow.com/questions/18770723
复制相似问题