Skip to content

Instantly share code, notes, and snippets.

@skurhse
Last active May 11, 2023 19:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skurhse/ad4a1ef96660f7721e29b88c601ea5c6 to your computer and use it in GitHub Desktop.
Save skurhse/ad4a1ef96660f7721e29b88c601ea5c6 to your computer and use it in GitHub Desktop.
# Set the subscription you want to work with
az account set --subscription <subscription_name>
# Provide the name of your resource group and private endpoint network interface
resource_group="<resource_group_name>"
network_interface="<network_interface_name>"
# Get the private endpoints attached to the specified network interface
private_endpoints=$(az network private-endpoint list --resource-group $resource_group --query "[?networkInterfaces[?id=='$network_interface']].{Id:id}" --output tsv)
# Iterate through each private endpoint and retrieve the FQDNs
echo "Private Endpoint FQDNs:"
while read -r private_endpoint; do
private_endpoint_name=$(echo $private_endpoint | cut -d'/' -f9)
private_dns_zone=$(az network private-endpoint show --id $private_endpoint --query "privateDnsZoneConfigs[0].name" --output tsv)
fqdn=$(az network private-dns record-set a show --resource-group $resource_group --zone-name $private_dns_zone --name $private_endpoint_name --query "arecords[0].ipv4Address" --output tsv)
echo $fqdn
done <<< "$private_endpoints"dpoints = az network nic show --resource-group $resourceGroup --name $networkInterface --query "ipConfigurations[].privateIpAddress" --output tsv | Where-Object { $_.PrivateIpAllocationMethod -eq "PrivateEndpoint" }
# Iterate through each private endpoint and retrieve the FQDNs
Write-Host "Private Endpoint FQDNs:"
foreach ($privateEndpoint in $privateEndpoints) {
$privateEndpointName = ($privateEndpoint -split "/")[8]
$privateEndpointResourceId = az resource show --ids $privateEndpoint --query "id" --output tsv
$privateDnsZoneConfig = az resource show --ids $privateEndpointResourceId --query "properties.ipConfigurations[0].privateEndpoint.privateLinkServiceConnections[0].customDnsConfigs" --output json | ConvertFrom-Json
$privateDnsZone = $privateDnsZoneConfig[0].privateDnsZoneName
$fqdn = az network private-dns record-set a show --resource-group $resourceGroup --zone-name $privateDnsZone --name $privateEndpointName --query "arecords[0].ipv4Address" --output tsv
Write-Host $fqdn
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment