Hi guys!
This script queries shorturl’s to attempt to obtain the real address. This is useful for attempting to determining the actual website when a short URL is sent. For example, we use this at work to attempt to determine the final URL before viewing the site within the helpdesk, useful to prevent us landing on a potentially malicious site.
function Resolve-ShortURL {
<#
.SYNOPSIS
Function to resolve a short URL to the absolute URI - useful for spam / malicious site checking.
.DESCRIPTION
Function to resolve a short URL to the absolute URI
.PARAMETER ShortUrl
Specifies the ShortURL
.EXAMPLE
Resolve-ShortURL -ShortUrl https://bit.ly/2MRHUiE
.EXAMPLE
Resolve-ShortURL -ShortUrl https://bit.ly/2MRHUiE
#>
[CmdletBinding()]
[OutputType([System.String])]
PARAM
(
[String[]]$ShortUrl
)
FOREACH ($URL in $ShortUrl) {
TRY {
Write-Verbose -Message "$URL - Querying..."
(Invoke-WebRequest -Uri $URL -MaximumRedirection 0 -ErrorAction Ignore).Headers.Location
}
CATCH {
$PSCmdlet.ThrowTerminatingError($_)
}
}
}