1

Has anyone managed to use Azure Resource Graph Query (Search-AzGraph PowerShell) to retrieve ALL DNS Records of every Private DNS Zone?

I believe there must be a way of getting DNS records related to object: "microsoft.network/privatednszones"

Resource Graph Query is faster than the regular az cli/azure powershell modules, but I have struggled to find anything online to write this query. It must be possible!

1 Answers1

2

We tested this in our local environment, Below statements are based on our analysis.

Using Search-AzGraph query, We can pull only the count of numberofRecordsSets under a particular Private DNS zone & respective DNS records are not populated in any of the columns as shown in the below image.

Here is the Search-AzGraph query we have used :

Search-AzGraph "project id, name, type,properties | where type =~ 'microsoft.network/privatednszones' "    

enter image description here

Alternatively, you can use the below REST API or PowerShell script to pull the DNS Record Sets of a particular private DNS Zone.

REST API:

GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/privateDnsZones/{privateZoneName}/ALL?api-version=2018-09-01

Here is the Powershell script:

$zonelist=Get-AzPrivateDnsZone
foreach ( $item in $zonelist)
{
    Get-AzPrivateDnsRecordSet -ResourceGroupName $item.ResourceGroupName -ZoneName $item.Name| select -property Name,RecordType,Records,ZoneName
}

Here is the sample output for reference:

enter image description here

VenkateshDodda
  • 4,723
  • 1
  • 3
  • 12
  • 1
    Thanks for clarifying that is isn't possible via Search-AzGraph. It's a shame, because from a performance perspective, it would have been the best option. I implemented plan B, which was to loop through using "Get-AzPrivateDnsRecordset". My script is no longer quick, but at least it has access to the information! Many Thanks :-) – Research Stuff Feb 25 '22 at 10:52
  • @ResearchStuff - If my answer is helpful for you, you can accept it as answer( click on the check mark beside the answer to toggle it from greyed out to filled in.). This can be beneficial to other community members. Thank you – VenkateshDodda Feb 25 '22 at 10:53