Using Invoke-webrequest to download a zip file

Tagged: 

This topic contains 1 reply, has 1 voice, and was last updated by Profile photo of Greg Martin Greg Martin 1 year, 7 months ago.

  • Author
    Posts
  • #25888
    Profile photo of Greg Martin
    Greg Martin
    Participant

    I'm looking to download a zip file from a website. I can do that using something like this:

    invoke-webrequest "$sourceURI" -outfile "$destinationfilename"

    however, I would like to see the headers.

    I know I can capture the output in a variable like so:

    $output = invoke-webrequest "$source$dailyfilename" -outfile "$destination$dailyfilename"

    But it is always empty when I use outfile.

    So if I skip the outfile, how do I get the content stream into a file?

    Thx!

  • #25890
    Profile photo of Greg Martin
    Greg Martin
    Participant

    Spoke with Jeff Hicks on Twitter (@JeffHicks) and he gave this solution:

    $output = invoke-webrequest "$sourceURI" -outfile "$destinationfilename" -passthru | select -Expand headers

    With this $output has the headers for my subsequent use.

You must be logged in to reply to this topic.