Skip to content

Instantly share code, notes, and snippets.

@p0w3rsh3ll
Created December 14, 2018 12:54
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 p0w3rsh3ll/a3690c1c275616ef06d4f300d0509aaa to your computer and use it in GitHub Desktop.
Save p0w3rsh3ll/a3690c1c275616ef06d4f300d0509aaa to your computer and use it in GitHub Desktop.
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