Skip to content

Instantly share code, notes, and snippets.

@markekraus
Created July 15, 2020 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markekraus/672029b6887b50b62660a3258839a89b to your computer and use it in GitHub Desktop.
Save markekraus/672029b6887b50b62660a3258839a89b to your computer and use it in GitHub Desktop.
PowerShell Core HTTP Redircet Capture
# 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