GinShell.GoDaddy/Public/Update-GsGoDaddyPointer.ps1

function Update-GsGoDaddyPointer {
    <#
    .SYNOPSIS
        Updates an existing DNS record (A or CNAME) via the GoDaddy API.
    .PARAMETER FullDomainName
        Fully qualified domain name (e.g., app.example.com).
    .PARAMETER Type
        DNS record type: A or CNAME. Default: CNAME.
    .PARAMETER Target
        The new target value.
    .EXAMPLE
        Update-GsGoDaddyPointer -FullDomainName 'app.example.com' -Target '10.0.0.5' -Type A
    #>

    [CmdletBinding(SupportsShouldProcess)]
    param (
        [Parameter(Mandatory)]
        [string]$FullDomainName,

        [ValidateSet('A', 'CNAME')]
        [string]$Type = 'CNAME',

        [Parameter(Mandatory)]
        [string]$Target
    )

    $dns     = Resolve-GoDaddyDomain -FullDomainName $FullDomainName
    $headers = Get-GoDaddyHeaders
    $uri     = "https://api.godaddy.com/v1/domains/$($dns.Domain)/records/$Type/$($dns.Name)"

    # Verify record exists
    $existing = $null
    try { $existing = Invoke-RestMethod -Uri $uri -Headers $headers -Method GET -ErrorAction Stop } catch {}

    if (-not $existing) {
        Write-GsLog -Message "Record '$FullDomainName' ($Type) does not exist. Cannot update." -Type Error
        return
    }

    if (-not $PSCmdlet.ShouldProcess($FullDomainName, "Update $Type record to '$Target'")) { return }

    $body = @(@{ data = $Target; name = $dns.Name; ttl = 3600; type = $Type }) | ConvertTo-Json -Depth 3

    try {
        Invoke-RestMethod -Uri $uri -Headers $headers -Method PUT -Body "[$body]" -ContentType 'application/json' -ErrorAction Stop
        Write-GsLog -Message "Updated $($dns.Name).$($dns.Domain) -> $Target" -Type Success
    }
    catch {
        Write-GsLog -Message "Failed to update record: $_" -Type Error
    }
}