move private dns group from one subscription to another

Arif Usman 431 Reputation points
2024-11-15T17:57:15.92+00:00

Folks,

I have a private DNS zone group with over 500 record sets. I need to move these record sets to another subscription. Is there an automated way to accomplish this?

Manually, I would need to open each individual private endpoint from recordsets and delete and add records, but with over 500 endpoints, this is time-consuming and inefficient.

I've written a script to automate this process, but it's not working. All the variables are correct and the resources exist, but no errors are being returned.

foreach ($endpointName in $endpointNames) {
    Write-Host "Processing Private Endpoint: $endpointName"

    $endpointNameWithEndpt = "$endpointName-endpt"

    az account set --subscription $Subscriptiondev

    # Get private endpoint details
    $privateEndpoint = Get-AzPrivateEndpoint -Name $endpointNameWithEndpt 
    $resourceGroupName = $privateEndpoint.ResourceGroupName
    Write-Host "Resource Group: $resourceGroupName"

    # Fetch DNS zone group details
    $dnsZoneGroup = az network private-endpoint dns-zone-group list `
        --endpoint-name $endpointNameWithEndpt `
        --resource-group $resourceGroupName `
        --query "[].privateDnsZoneConfigs[].privateDnsZoneId" -o json | ConvertFrom-Json

    if ($dnsZoneGroup) {
        foreach ($dnsZoneId in $dnsZoneGroup) {
            $dnsZoneName = ($dnsZoneId -split "/")[-1]
            Write-Host "Found Private DNS Zone: $dnsZoneName"

            Write-Host "Removing DNS Zone: $dnsZoneName from endpoint: $endpointNameWithEndpt"
            
            az network private-endpoint dns-zone-group remove `
                --resource-group $resourceGroupName `
                --endpoint-name $endpointNameWithEndpt `
                --zone-name $dnsZoneName `
                --name "default" `
                --subscription $Subscriptiondev   
        }
    } else {
        Write-Host "No DNS zones associated with $endpointNameWithEndpt"
    }
}

Azure DNS
Azure DNS
An Azure service that enables hosting Domain Name System (DNS) domains in Azure.
696 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Vahid Ghafarpour 21,890 Reputation points
    2024-11-16T04:08:21.8266667+00:00
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.