-
-
Save p0w3rsh3ll/a3690c1c275616ef06d4f300d0509aaa to your computer and use it in GitHub Desktop.
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
Function Get-URINewLocation { | |
[CmdletBinding()] | |
Param( | |
[Parameter(Mandatory)] | |
[system.URI]$URI | |
) | |
Begin { | |
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 | |
} | |
Process { | |
$HT = @{ | |
URI = $URI | |
UseBasicParsing = [switch]::Present | |
MaximumRedirection = 0 | |
ErrorAction = 'SilentlyContinue' | |
} | |
$r = (Invoke-WebRequest @HT -Verbose:$false) | |
Write-Verbose -Message "Testing URI: $($URI)" | |
if ($r.StatusCode -eq 301) { | |
Write-Verbose -Message "New permanent location found $($r.Headers.Location)" | |
Get-URINewLocation -URI "$($r.Headers.Location)" | |
} elseif ($r.StatusCode -eq 302 -and $r.StatusDescription -eq 'Moved Temporarily') { | |
Write-Verbose -Message "New temp location found $($r.Headers.Location)" | |
Get-URINewLocation -URI "$($r.Headers.Location)" | |
} elseif ($r.StatusCode -eq 302 -and $r.StatusDescription -eq 'Found') { | |
$($r.Headers.Location) | |
} else { | |
Write-Warning -Message "Error code is $($r.StatusCode)" | |
} | |
} | |
End {} | |
} | |
Get-URINewLocation -URI 'https://go.microsoft.com/fwlink/?linkid=850641' -Verbose |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment