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


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/” -OutFile “$DOWNLOAD_PATH\”

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<span style=“font-size: 10pt;font-family: ‘courier new’, courier, monospace”>

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


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


# set Download path


$API_KEY = ‘yourAPIkey’

URL to file


file to download

$download_file = “”

set up the .net webclient

$Wget = New-Object System.Net.WebClient

add headers

$Wget.Headers[“X-JFrog-Art-Api”] = $API_KEY

download the file

$Wget.DownloadFile(“$COMPONENT/$download_file” , “$DOWNLOAD_PATH$download_file”)