Public/Curanet/DNS/New-CuranetDNSRecord.ps1

function New-CuranetDNSRecord {
    <#
        .SYNOPSIS
            Command to create a new DNS record
 
        .PARAMETER DomainName
            String containing domainname
 
        .PARAMETER Hostname (Optional, default empty)
            String containing hostname of the DNS record - Should not include the domainname
 
        .PARAMETER Type
            String containing the type of the DNS record.
         
        .PARAMETER TTL (Optional, default 3600)
            Integer containing the Time To Live value.
         
        .PARAMETER Priority (Optional, default 0)
            Integer containing the Priority value.
         
        .PARAMETER Value
            String containing the value of the record.
         
        .OUTPUTS
            Object containing the DNS record OR error.
         
        .EXAMPLE
            $domain = "example.com"
            $hostname = "www"
            $type = "A"
            $value = "11.22.33.44"
            New-CuranetDNSRecord -DomainName $domain -Hostname $hostname -Type $type -Value $value
 
            This example creates a new A record for "www.example.com".
 
        .EXAMPLE
            New-CuranetDNSRecord -DomainName "test.com" -Type "MX" -Value "mail.test.com"
 
            This example creates a new MX record for "test.com".
    #>

    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$true)]
        [string]
        $DomainName,

        [Parameter()]
        [string]
        $Hostname,

        [Parameter(Mandatory=$true)]
        [string]
        $Type,

        [Parameter()]
        [int]
        $TTL = 3600,

        [Parameter()]
        [int]
        $Priority = 0,

        [Parameter(Mandatory=$true)]
        [string]
        $Value
    )

    if( $Hostname -ne '') {
        $Name = "$($Hostname).$($DomainName)"
    }

    else {
        $Name = $DomainName
    }

    $Body = @{
        name        = $Name
        type        = $Type.ToUpper()
        ttl         = $TTL
        priority    = $Priority
        data        = $Value
    }

    return Invoke-CuranetAPI "3370" -Uri "https://api.curanet.dk/dns/v2/Domains/$($DomainName)/Records" -Method "POST" -Body $Body
}