Invoke-WebRequest sometimes does not download the complete zip or msi file

Welcome Forums General PowerShell Q&A Invoke-WebRequest sometimes does not download the complete zip or msi file

Viewing 1 reply thread
  • Author
    Posts
    • #252668
      Participant
      Topics: 10
      Replies: 9
      Points: 139
      Rank: Participant

      Hi,

      I have external repository from where I need to download my installation files. They are in zip or msi format – for both I noticed that SOMETIMES (about 50%) it does not download them properly.

      Invoke-WebRequest -Headers @{‘X-JFrog-Art-Api’=$API_KEY} “$COMPONENT/PowerShell_7_0_0.zip” -OutFile “$DOWNLOAD_PATH\PowerShell_7_0_0.zip”

      Because of that my file is not useful, it’s invalid.

      I know I can check it “checksum” and compare it with expected value:

      (Get-FileHash -Algorithm SHA256 C:\Octopus\Applications\PowerShell_7_0_0.zip).Hash

      But isn’t there some better way how I can overcome this? Maybe some built-in TimeOut or Retry for Invoke-WebRequest… or maybe to use some other method… I do not know…

      But this is really a big issue which I suppose someone already encountered and resolved it..

      I will appreciate very much your assistance. Thanks

       

    • #252989
      Participant
      Topics: 0
      Replies: 8
      Points: 48
      Rank: Member

      I’ve used the native .Net webclient in the past to download files. This following script will hopefully help;

       

Viewing 1 reply thread
  • You must be logged in to reply to this topic.