Why is my invoke-webrequest command downloading a corrupt file?

0
4
Asked By CuriousCat42 On

I'm trying to download application installers directly using PowerShell's invoke-webrequest instead of using winget or doing manual downloads. However, I'm facing an issue where the file I'm downloading seems corrupt and fails to run. Here's the command I've been using:

```powershell
invoke-webrequest -Uri https://download-installer.cdn.mozilla.net/pub/firefox/releases/138.0.1/win32/en-US/Firefox%20Installer.exe | out-file C:tempff2.exe
```

I also included a link with an image of the error I'm facing. I've read that using the -OutFile parameter might help, as shown in an edit I made, but I'm curious what exactly I should be doing to fix the downloading issue and ensure the installer works. Thanks for any insights!

1 Answer

Answered By TechWhiz_99 On

You should be using the -OutFile parameter directly with invoke-webrequest instead of piping it to Out-File. It tends to handle the downloads more reliably that way. Also, try adding `$progresspreference='SilentlyContinue'` to speed up the process a bit!

CuriousCat42 -

Thanks for that tip! I'm curious, though—why does the -OutFile parameter work while piping to Out-File doesn't? It seems a bit odd.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.