Hide progress of Invoke-WebRequest

前端 未结 1 1911
一向
一向 2020-12-05 09:09

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

相关标签:
1条回答
  • 2020-12-05 09:32

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

    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.
    
    0 讨论(0)
提交回复
热议问题