resolve-uri.ps1
<#PSScriptInfo
.VERSION 1.0 .GUID 52a3719b-0d47-402e-a538-9a1623be12f2 .AUTHOR Lee Holmes .DESCRIPTION Resolve a URI to the URIs it redirects to #> <# .Synopsis Resolve a URI to the URIs it redirects to .EXAMPLE PS> Resolve-Uri https://bitly.is/1g3AhR6 https://bitly.is/1g3AhR6 https://bitly.com/ #> param( ## The URI to resolve [Parameter(Mandatory, Position = 0)] $Uri ) $ProgressPreference = "Ignore" while($Uri) { try { $Uri $null = Invoke-Webrequest $Uri -UseBasicParsing -MaximumRedirection 0 $Uri = $null } catch { $Uri = $_.Exception.Response.Headers.Location.OriginalString if(-not $Uri) { throw $_ } } } |