Created
July 15, 2020 15:11
-
-
Save markekraus/672029b6887b50b62660a3258839a89b to your computer and use it in GitHub Desktop.
PowerShell Core HTTP Redircet Capture
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# PowerShell 7 | |
$uri = 'https://microsoft.com' | |
$result = Invoke-WebRequest -SkipHttpErrorCheck -Uri $uri -MaximumRedirection 0 -ErrorAction SilentlyContinue -ErrorVariable $err | |
$location = $result.Headers.Location | |
# PowerShell 6 | |
$uri = 'https://microsoft.com' | |
try { | |
Invoke-WebRequest -Uri $uri -MaximumRedirection 0 -ErrorAction Stop | |
} catch { | |
$location = $_.Exception.Response.Headers.Location | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment