Trouble Downloading Files with Invoke-WebRequest in PowerShell

0
2
Asked By CuriousCoder123 On

Hey everyone! I need some help with a PowerShell command I use to download files from various manufacturers. I typically pull the URLs from an Excel sheet, where I have a formula that generates the command:="Invoke-WebRequest -Uri "&CAR(34)&A1&C AR(34)&" -OutFile "&CAR(34)&B1&"\"&D1&CAR(34). Most of the time it works perfectly, but occasionally, I'll end up with a 0kb file or something that's unreadable. For instance, I tried downloading this URL: https://faro.es/content/comun/ficha.php?ref=01001&idioma=fr, and I get an unreadable PDF. I can't manually download each link since there are too many. Any suggestions on how to tackle this issue directly from the command line? Thanks in advance!

1 Answer

Answered By HelpfulHank99 On

It sounds like you might be hitting a restriction from the server. Have you checked the error messages when running your command? If it gives a 403 Forbidden, that could mean the site is blocking automated requests. In PowerShell 7, you can use the –SkipHttpErrorCheck flag to see the StatusCode property. It's possible they're employing anti-bot measures, so that might be why some files are 0kb or unreadable.

ExcelMaster42 -

I didn’t get an error when trying it with the URL you mentioned. My command was: Invoke-WebRequest -Uri "https://faro.es/content/comun/ficha.php?ref=01001&idioma=fr" -OutFile "c:FAROFARO.pdf". The file came out to 167kb, but it's definitely not a valid PDF, looks more like a web page instead.

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.