隐藏 Invoke-WebRequest 的进度 [英] Hide progress of Invoke-WebRequest
问题描述
如何隐藏Invoke-WebRequest
的进度显示?我做了很多连续的请求,并且有我自己使用的 Write-Progress
显示,所以我不需要每次都在它下面弹出内置的.
How can I hide the progress display of Invoke-WebRequest
? I do a lot of successive requests and have my own Write-Progress
display that I use, so I don't need the built-in one popping up underneath it every time.
我使用自动从 Invoke-WebRequest
的结果创建的 mshtml 结果(IE COM 对象),所以我无法切换到 WebClient
或类似的东西,除非有人提供有关如何从 WebClient 请求获取 mshtml 对象的说明.
I use the mshtml results (the IE COM object) that are created from the result of Invoke-WebRequest
automatically, so I can't switch to a WebClient
or something like that, unless someone provides instructions on how to get an mshtml object from a WebClient request.
推荐答案
使用 $progressPreference 变量.默认情况下,它的值应该为继续",除非您在其他地方对其进行了编辑,这会告诉 Powershell 显示进度条.既然你提到你有自己的自定义进度显示,我会在 cmdlet 执行后立即重置它.例如:
Use the $progressPreference variable. It should have a value of 'Continue' by default unless you've edited it elsewhere, which tells Powershell to display the progress bar. Since you mentioned that you have your own custom progress displays, I would reset it immediately after the cmdlet is executed. For example:
$ProgressPreference = 'SilentlyContinue' # Subsequent calls do not display UI.
Invoke-WebRequest ...
$ProgressPreference = 'Continue' # Subsequent calls do display UI.
Write-Progress ...
在 about_preference_variables 上有关首选项变量的更多信息.这是 $ProgressPreference 的条目:
More info on preference variables at about_preference_variables. Here's the entry for $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.
这篇关于隐藏 Invoke-WebRequest 的进度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!