Подтвердить что ты не робот

Скрыть ход Invoke-WebRequest

Как я могу скрыть отображение прогресса Invoke-WebRequest? Я делаю много последовательных запросов и имею свой собственный Write-Progress дисплей, который я использую, поэтому мне не нужен встроенный, который появляется каждый раз под ним.

Я использую результаты mshtml (объект COM COM), которые создаются из результата Invoke-WebRequest автоматически, поэтому я не могу переключиться на WebClient или что-то в этом роде, если только кто-то не дает инструкции о том, как получить объект mshtml из запроса WebClient.

4b9b3361

Ответ 1

Используйте переменную $progressPreference. Он должен иметь значение "Продолжить" по умолчанию, если вы не отредактировали его в другом месте, что говорит Powershell о отображении индикатора выполнения. Поскольку вы упомянули, что у вас есть собственные пользовательские индикаторы прогресса, я бы reset сразу после выполнения командлета. Например:

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