TNT TNT - 3 months ago 30
PowerShell Question

Is there really no way to prevent Invoke-WebRequest from following redirections

It seems the

Invoke-WebRequest
cmdlet provides no way to inspect redirecting responses (by saying "don't follow redirections"). This would make the
curl
-alias not only ridiculous but even more than superfluous.

Can anybody spare me this disappointment?

Answer

Use the MaximumRedirection parameter to prevent implicit redirects from occuring:

Invoke-WebRequest http://www.google.com -MaximumRedirection 0