如何隐藏Invoke-WebRequest
的进度显示?我做了很多连续的请求并且使用了我自己的Write-Progress
显示器,所以我不需要每次都在它下面弹出一个内置的显示器。
我使用根据Invoke-WebRequest
的结果自动创建的mshtml结果(IE COM对象),因此我无法切换到WebClient
或类似的东西,除非有人提供说明关于如何从WebClient请求中获取mshtml对象。
答案 0 :(得分:60)
使用$ progressPreference变量。默认情况下,它应该具有“继续”值,除非您在别处编辑它,这告诉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.