-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathGet-ShortenedURL
More file actions
70 lines (48 loc) · 1.94 KB
/
Get-ShortenedURL
File metadata and controls
70 lines (48 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
Function Get-ShortenedURL {
<#
.SYNOPSIS
Get-ShortenedURL
Author: Chris Campbell (@obscuresec)
License: BSD 3-Clause
.DESCRIPTION
A function that returns the actual URL from a http redirect.
.PARAMETER $ShortenedURL
Specifies the shortened URL.
.EXAMPLE
PS C:\> Get-ShortenedURL -ShortenedURL http://goo.gl/V4PKq
PS C:\> Get-ShortenedURL -ShortenedURL http://goo.gl/V4PKq,http://bit.ly/IeWSIZ
PS C:\> Get-Content C:\urls.txt | Get-ShortenedURL
PS C:\> Get-ShortenedURL -ShortenedURL (Get-Content C:\urls.txt)
.LINK
http://obscuresecurity.blogspot.com/2013/01/Get-ShortenedURL.html
https://github.com/obscuresec/random/blob/master/Get-ShortenedURL
#>
[CmdletBinding()] Param(
[Parameter(Mandatory=$True,ValueFromPipeline=$True)]
[string[]] $ShortenedURL
)
BEGIN {}
PROCESS {
Try {
#Loop through each URL in the array
Foreach ($URL in $ShortenedURL) {
#Create the WebClient Object and request
$WebClientObject = New-Object System.Net.WebClient
$WebRequest = [System.Net.WebRequest]::create($URL)
$WebResponse = $WebRequest.GetResponse()
#Parse out redirected URL
$ActualDownloadURL = $WebResponse.ResponseUri.AbsoluteUri
#Create custom object to store results
$ObjectProperties = @{ 'Shortened URL' = $URL;
'Actual URL' = $ActualDownloadURL}
$ResultsObject = New-Object -TypeName PSObject -Property $ObjectProperties
#Output the results
Write-Output $ResultsObject
#Close the webclient connection
$WebResponse.Close()
}
}
Catch {}
}
END {}
}