Andy Levy shows how to handle complex redirects with Invoke-WebRequest in Powershell:
So off to the PowerShell prompt I went and ran
Invoke-WebRequest -Urihttp://firstresponderkit.org/to start looking at the object returned so I could see what I needed to parse out to find my way to the true download URL.Then Firefox (my default browser) opened, and I was staring at
https://github.com/BrentOzarULTD/SQL-Server-First-Responder-Kit/tree/master.I was expecting an
HTTP 30Xredirect status code which, based upon previous experience,Invoke-WebRequestwould honor. Instead, I got a200 OKwhich is the web server saying “yep, here’s your stuff, HAND!”
Read on for the solution.