How do I overcome this ?
Found this answer by Alec Collier
Add the following to your URL call : -MaximumRedirection 0 -ErrorAction Ignore
Example :
$url="https://jigsaw.w3.org/HTTP/300/301.html"
$resp = Invoke-WebRequest $url -MaximumRedirection 0 -ErrorAction Ignore
$resp.Headers.Location
                        Just use -MaximumRedirection 0 -SkipHttpErrorCheck (and add -ErrorAction:SilentlyContinue if you want to suppress the warning):
(Invoke-WebRequest -Uri "https://www.google.com/ncr" -MaximumRedirection 0 -SkipHttpErrorCheck -ErrorAction:SilentlyContinue).Headers.Location
https://www.google.com/
Note that the data type of return value is an array and it only has a single item.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With