What kind of error Invoke-WebRequest produces then it's always end up in output?

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Curtis Smith Curtis Smith 5 days, 22 hours ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #54451
    Profile photo of GS
    GS
    Participant

    I'm trying to figure out what exactly Invoke-WebRequest cmdlet doing differently then other cmdlets as far as error output is concerned. If you execute it with non-existing URL then you end up with errors being put out into output stream. I assume if I use -ErrorAccount parameter to Silent then it will not show up in stream but it does not work. The same happens if I redirect output to Out-Null. Errors are still end up in a stream. What exactly is happening behind the scenes here?

    Invoke-WebRequest http://www.cnn.com/nonexist.htm -ErrorAction Silent | out-null
    • This topic was modified 6 days, 10 hours ago by Profile photo of GS GS.
    #54503
    Profile photo of Curtis Smith
    Curtis Smith
    Participant

    Hey GS,
    Difference is that invoke-webrequest is throwing a Terminating Error
    TerminatingError(Invoke-WebRequest)

    You can see this by using Start-Transcript and Stop-Transcript

    Start-Transcript
        Invoke-WebRequest http://www.cnn.com/nonexist.htm
        Get-Content c:\asdfas.fasdf
    Stop-Transcript
    

    If you need to catch a terminating error, use try{} catch{}

    Start-Transcript
        try{Invoke-WebRequest http://www.cnn.com/nonexist.htm}
        catch{"Invoke-WebReqeust returned a terminating error"}
    Stop-Transcript
    
    • This reply was modified 5 days, 22 hours ago by Profile photo of Curtis Smith Curtis Smith.
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.