|
1 | 1 | function Set-AzDnsAsCodeConfig
|
2 |
| -{ |
| 2 | +{ |
3 | 3 | <#
|
4 | 4 | .SYNOPSIS
|
5 | 5 | Execute a request against the Azure Management Api to set DNS Entries
|
|
9 | 9 |
|
10 | 10 | .EXAMPLE
|
11 | 11 | PS C:\> Set-AzDnsAsCodeConfig -Method PUT -Type A -DNSZone contoso.com -Domain api -TTL 3600 -Target 127.0.0.1
|
| 12 | +
|
| 13 | + Set up a new DNS Config for one DNS entry |
12 | 14 | #>
|
13 | 15 |
|
14 | 16 | [CmdletBinding(DefaultParameterSetName='default')]
|
|
17 | 19 | [Parameter (Mandatory=$false)][ValidateSet('A','AAAA','CNAME','MX','NS','SOA','SRV','TXT','PTR')][string]$Type,
|
18 | 20 | [Parameter (Mandatory=$true)][ValidatePattern("^((?!-))(xn--)?[a-z0-9][a-z0-9-_]{0,61}[a-z0-9]{0,1}\.(xn--)?([a-z0-9\-]{1,61}|[a-z0-9-]{1,30}\.[a-z]{2,})$")]$DNSZone,
|
19 | 21 | [Parameter (Mandatory=$false)][ValidatePattern("(^@)|\w+")][string]$Domain,
|
20 |
| - [Parameter (Mandatory=$false)][int]$TTL, |
| 22 | + [Parameter (Mandatory=$false)][int]$TTL, |
21 | 23 | [string]$Target,
|
22 |
| - # MX Paramter |
| 24 | + # MX Paramter |
23 | 25 | [Parameter(ParameterSetName='MX', Mandatory=$true)][int]$MXPreference,
|
24 |
| - # SRV Paramter |
| 26 | + # SRV Paramter |
25 | 27 | [Parameter(ParameterSetName='SRV', Mandatory=$true)][int]$SRVPort,
|
26 | 28 | [Parameter(ParameterSetName='SRV', Mandatory=$true)][int]$SRVweight,
|
27 | 29 | [Parameter(ParameterSetName='SRV', Mandatory=$true)][int]$SRVPriority,
|
|
31 | 33 | [Parameter(ParameterSetName='SOA')][string]$SOAserialnumber,
|
32 | 34 | [Parameter(ParameterSetName='SOA')][string]$SOArefreshtime,
|
33 | 35 | [Parameter(ParameterSetName='SOA')][string]$SOAretrytime,
|
34 |
| - [Parameter(ParameterSetName='SOA')][string]$SOAexpireTime, |
| 36 | + [Parameter(ParameterSetName='SOA')][string]$SOAexpireTime, |
35 | 37 | [Parameter(ParameterSetName='SOA')][string]$SOAminimumTTL,
|
36 | 38 | $body, # for Multivalue Entries
|
37 | 39 | [switch]$outputEnabled = $false,
|
38 | 40 | # Azure required Parameters
|
39 |
| - [Parameter (Mandatory=$false)][String]$ApiVersion = '2018-05-01', |
40 | 41 | [Parameter (Mandatory=$true)][String]$SubscriptionID,
|
41 | 42 | [Parameter (Mandatory=$true)][String]$TenantId,
|
42 | 43 | [Parameter (Mandatory=$true)][String]$ResourceGroup
|
43 | 44 | )
|
44 | 45 |
|
45 | 46 |
|
46 | 47 | #region URL
|
47 |
| - |
48 |
| - $uri = "https://management.azure.com/subscriptions/$SubscriptionId/resourceGroups/$ResourceGroup/providers/Microsoft.Network/dnszones/$DNSZone/$Type/$($Domain)?api-version=$APIversion" |
| 48 | + $uri = "https://management.azure.com/subscriptions/$SubscriptionId/resourceGroups/$ResourceGroup/providers/Microsoft.Network/dnszones/$DNSZone/$Type/$($Domain)?api-version=$($script:APIversion)" |
49 | 49 | #endregion URL
|
50 | 50 | #region Body
|
51 |
| - if (-not $body) { |
| 51 | + if (-not $body) { |
52 | 52 | $ScriptDir = Split-Path $script:MyInvocation.MyCommand.Path
|
53 | 53 | $body = Get-Content $ScriptDir\internal\configurations\body.json | ConvertFrom-Json
|
54 | 54 | if ($Method -eq 'PUT') {
|
55 | 55 | switch ($type) {
|
56 |
| - A { |
57 |
| - #Var setzen |
| 56 | + A { |
| 57 | + #Var setzen |
58 | 58 | $body.$Method.$type.Value.properties.ARecords[0].ipv4Address = $Target
|
59 | 59 | $body.$Method.$type.Value.properties.TTL = $TTL
|
60 | 60 | $body.$Method.$type.Value.properties.metadata.Key1 = $Domain
|
61 | 61 | $body = $body.$Method.$Type.Value | ConvertTo-Json -Depth 10
|
62 | 62 | }
|
63 |
| - AAAA { |
64 |
| - #Var setzen |
| 63 | + AAAA { |
| 64 | + #Var setzen |
65 | 65 | $body.$Method.$type.Value.properties.AAAARecords[0].ipv6Address = $Target
|
66 | 66 | $body.$Method.$type.Value.properties.TTL = $TTL
|
67 | 67 | $body.$Method.$type.Value.properties.metadata.Key1 = $Domain
|
|
73 | 73 | $body.$Method.$type.Value.properties.TTL = $TTL
|
74 | 74 | $body.$Method.$type.Value.properties.metadata.Key1 = $Domain
|
75 | 75 | $body = $body.$Method.$Type.Value | ConvertTo-Json -Depth 10
|
76 |
| - |
77 | 76 | }
|
78 | 77 | MX {
|
79 | 78 | #Var setzen
|
|
82 | 81 | $body.$Method.$type.Value.properties.TTL = $TTL
|
83 | 82 | $body.$Method.$type.Value.properties.metadata.Key1 = $Domain
|
84 | 83 | $body = $body.$Method.$Type.Value | ConvertTo-Json -Depth 10
|
85 |
| - |
86 | 84 | }
|
87 | 85 | NS {
|
88 | 86 | #Var setzen
|
|
134 | 132 | else {
|
135 | 133 | $response = AzAPICall -uri $uri -method $Method -body $body -listenOn Content
|
136 | 134 | }
|
137 |
| - "Response:" |
138 |
| - #endregion API Call |
| 135 | + Write-Output "---------------------------------------------------------------------------------------------------" |
| 136 | + Write-Output "Response:" |
| 137 | + #endregion API Call |
139 | 138 | #region Output
|
140 | 139 | if ($Method -eq 'DELETE' -and [string]::IsNullOrWhiteSpace($response)) {"DELETE complete"}
|
141 |
| - else { |
142 |
| - if ($all) { "Anzahl Records: " + $response.value.Count |
143 |
| - $output = $response.Value | Select-Object name, ` |
144 |
| - @{Name = "Type"; Expression = {($_.properties | Get-Member | Where-Object {$_.Name -like "*Recor*"}).Name -replace "Records","" -replace "Record",""}}, ` |
145 |
| - @{Name = "TTL"; Expression = {"$($_.properties.TTL)"}}, ` |
146 |
| - @{Name = "Properties"; Expression = { [string]($_.properties | Select-Object -ExpandProperty "*Recor*")}}, ` |
147 |
| - @{Name = "MetaData"; Expression = {"$($_.properties.metadata)"}} | Format-Table -AutoSize |
| 140 | + else { |
| 141 | + if ($all) { "Anzahl Records: " + $response.value.Count |
| 142 | + $output = $response.Value | Select-Object name, ` |
| 143 | + @{Name = "Type"; Expression = {($_.properties | Get-Member | Where-Object {$_.Name -like "*Recor*"}).Name -replace "Records","" -replace "Record",""}}, ` |
| 144 | + @{Name = "TTL"; Expression = {"$($_.properties.TTL)"}}, ` |
| 145 | + @{Name = "Properties"; Expression = { [string]($_.properties | Select-Object -ExpandProperty "*Recor*")}}, ` |
| 146 | + @{Name = "MetaData"; Expression = {"$($_.properties.metadata)"}} | Format-Table -AutoSize |
148 | 147 | }
|
149 | 148 | else {
|
150 | 149 | $output = $response | Select-Object name, `
|
151 | 150 | @{Name = "Type"; Expression = {($_.properties | Get-Member | Where-Object {$_.Name -like "*Recor*"}).Name -replace "Records","" -replace "Record",""}}, `
|
152 | 151 | @{Name = "TTL"; Expression = {"$($_.properties.TTL)"}}, `
|
153 | 152 | @{Name = "Properties"; Expression = { [string]($_.properties | Select-Object -ExpandProperty "*Recor*")}}, `
|
154 | 153 | @{Name = "MetaData"; Expression = {"$($_.properties.metadata)"}} | Format-Table -AutoSize
|
155 |
| - } |
| 154 | + } |
156 | 155 | }
|
157 | 156 | #endregion Output
|
| 157 | + return $output |
158 | 158 | }
|
0 commit comments