powershell - 隐藏 Invoke-WebRequest 的进度

标签 powershell progress powershell-3.0

如何隐藏 Invoke-WebRequest 的进度显示?我做了很多连续的请求,并有我自己使用的 Write-Progress 显示,所以我不需要每次都在它下面弹出内置的。

我使用自动从 Invoke-WebRequest 的结果创建的 mshtml 结果(IE COM 对象),所以我不能切换到 WebClient 或类似的东西,除非有人提供有关如何从 WebClient 请求获取 mshtml 对象的说明.

最佳答案

使用 $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.

关于powershell - 隐藏 Invoke-WebRequest 的进度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46247608/

相关文章:

powershell - 如何区分未设置参数与 $false、0、空字符串?

powershell - 接收作业输出到文件

version-control - 捕获非标准 Powershell CmdLet 输出以进行流量控制

javascript - 多个进度圈同一个页面

powershell - 使用 Invoke-Command 格式化输出

java - 如何在 Java 中正确实现玻璃面板?

python - 如何在不使用多线程的情况下显示进度

uwp - 使用Powershell启动Metro风格的应用程序

powershell - 通过 .lnk 文件通过管道传输到可执行文件

powershell - 如何在 PowerShell 中内存一个函数?