-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathGet-GoDaddyDNS.ps1
58 lines (51 loc) · 1.65 KB
/
Get-GoDaddyDNS.ps1
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
<#
.Synopsis
Retrieves DNS records.
.DESCRIPTION
Retrieves DNS records for a domain hosted with GoDaddy.
.EXAMPLE
Get-GoDaddyDNS google.com
This example will return all DNS records for google.com.
.EXAMPLE
Get-GoDaddyDNS -Domain google.com | Where-Object {$_.Type -eq "A"}
This example will return all A records for google.com.
#>
function Get-GoDaddyDNS
{
Param
(
[Parameter(Mandatory=$true,
Position=0)]
[string]$Domain
)
Begin {
$apiKeySecure = Import-Csv "$PSScriptRoot\apiKey.csv"
# Decrypt API Key
$apiKey = @(
[PSCustomObject]@{
Key = [System.Net.NetworkCredential]::new("", ($apiKeySecure.Key | ConvertTo-SecureString)).Password
Secret = [System.Net.NetworkCredential]::new("", ($apiKeySecure.Secret | ConvertTo-SecureString)).Password
}
)
}
Process {
#---- Build authorization header ----#
$headers = @{}
$headers["Authorization"] = 'sso-key ' + $apiKey.key + ':' + $apiKey.secret
#---- Build the request URI based on domain ----#
$uri = "https://api.godaddy.com/v1/domains/$Domain/records"
#---- Make the request ----#
$request = Invoke-WebRequest -Uri $uri -Method Get -Headers $headers -UseBasicParsing | ConvertFrom-Json
#---- Convert the request data into an object ----#
foreach ($item in $request) {
[PSCustomObject]@{
data = $item.data
name = $item.name
ttl = $item.ttl
type = $item.type
}
}
}
End {
}
}