Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 隐藏调用WebRequest的进度_Powershell_Progress_Powershell 3.0 - Fatal编程技术网

Powershell 隐藏调用WebRequest的进度

Powershell 隐藏调用WebRequest的进度,powershell,progress,powershell-3.0,Powershell,Progress,Powershell 3.0,如何隐藏调用WebRequest的进度显示?我做了很多连续的请求,并且有我自己使用的写进度显示,所以我不需要每次都在下面弹出的内置进度 我使用的mshtml结果(IE COM对象)是根据调用WebRequest的结果自动创建的,因此我不能切换到WebClient或类似的东西,除非有人提供如何从WebClient请求获取mshtml对象的说明。使用$progressPreference变量。默认情况下,它的值应为“Continue”,除非您在其他位置编辑过它,这会告诉Powershell显示进度条

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


我使用的mshtml结果(IE COM对象)是根据
调用WebRequest
的结果自动创建的,因此我不能切换到
WebClient
或类似的东西,除非有人提供如何从WebClient请求获取mshtml对象的说明。

使用$progressPreference变量。默认情况下,它的值应为“Continue”,除非您在其他位置编辑过它,这会告诉Powershell显示进度条。因为您提到您有自己的自定义进度显示,所以我会在执行cmdlet后立即重置它。例如:

$ProgressPreference = 'SilentlyContinue'    # Subsequent calls do not display UI.
Invoke-WebRequest ...
$ProgressPreference = 'Continue'            # Subsequent calls do display UI.
Write-Progress ...
有关首选项变量的更多信息,请访问。以下是$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.

如果其他人对此有异议。。。如果调用其他脚本块,可能需要显式指定
$global:progressPreference='silentlyContinue'
$progressPreference='SilentlyContinue'和更高版本的
$progressPreference=$oldProgressPreference
还将保留以前的设置,这可以提高链接脚本时的一致性。@ChrisBaxter谢谢!如果没有
$global
位,当我直接在CI配置中编写命令时,它对我来说工作正常,但一旦我将其移动到powershell脚本中,它就停止工作。设置全局变量将其正确修复!请注意,隐藏progressbar时,性能要比隐藏progressbar好几个数量级。我等了几分钟才取消