Public/Add-DynDnsRecord.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 |
function Add-DynDnsRecord { [CmdLetBinding( SupportsShouldProcess=$true, ConfirmImpact='High' )] param( [Parameter(Mandatory=$true)] [string]$Zone, [string]$Node, [Parameter(Mandatory=$true)] [DynDnsRecord]$DynDnsRecord ) if (-Not (Test-DynDnsSession)) { return } if ($DynDnsRecord.record_type -eq 'SOA') { Write-Warning -Message 'You cannot add a new SOA record with this command. Please use Update-DynDnsRecord to update the ResponsiblePerson, SerialStyle, or TTL.' return } if ($Node) { if ($Node -match $Zone ) { $Fqdn = $Node } else { $Fqdn = $Node + '.' + $Zone } } else { $Fqdn = $Zone } $UriPath = "/REST/$($DynDnsRecord.Type)Record/$Zone/$Fqdn/" $DynDnsRecord.RawData.Remove('record_type') $JsonBody = $DynDnsRecord.RawData | ConvertTo-Json if ($PSCmdlet.ShouldProcess("$($DynDnsRecord.Type) - $Fqdn","Adding DNS record")) { $NewHttpRedirect = Invoke-DynDnsRequest -UriPath $UriPath -Method Post -Body $JsonBody Write-DynDnsOutput -DynDnsResponse $NewHttpRedirect } else { Write-Verbose 'Whatif : Added DNS record' } } |