Skip to content

Commit 7d87adf

Browse files
authored
Merge pull request #95114 from SnehaGunda/master
Adding Private Zones PowerShell script
2 parents 3325cae + 161e54b commit 7d87adf

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

articles/cosmos-db/how-to-configure-private-endpoints.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,41 @@ $subnet = $virtualNetwork | Select -ExpandProperty subnets | Where-Object {$_.N
124124
$privateEndpoint = New-AzPrivateEndpoint -ResourceGroupName $ResourceGroupName -Name $PrivateEndpointName -Location "westcentralus" -Subnet $subnet -PrivateLinkServiceConnection $privateEndpointConnection
125125
```
126126

127+
### Integrate the private endpoint with private DNS zone
128+
129+
After you create the private endpoint, you can integrate it with a private DNS zone by using the following PowerSehll script:
130+
131+
```azurepowershell-interactive
132+
Import-Module Az.PrivateDns
133+
$zoneName = "privatelink.documents.azure.com"
134+
$zone = New-AzPrivateDnsZone -ResourceGroupName $ResourceGroupName `
135+
-Name $zoneName
136+
137+
$link = New-AzPrivateDnsVirtualNetworkLink -ResourceGroupName $ResourceGroupName `
138+
-ZoneName $zoneName `
139+
-Name "myzonelink" `
140+
-VirtualNetworkId $virtualNetwork.Id
141+
142+
$pe = Get-AzPrivateEndpoint -Name $PrivateEndpointName `
143+
-ResourceGroupName $ResourceGroupName
144+
145+
$networkInterface = Get-AzResource -ResourceId $pe.NetworkInterfaces[0].Id `
146+
-ApiVersion "2019-04-01"
147+
148+
foreach ($ipconfig in $networkInterface.properties.ipConfigurations) {
149+
foreach ($fqdn in $ipconfig.properties.privateLinkConnectionProperties.fqdns) {
150+
Write-Host "$($ipconfig.properties.privateIPAddress) $($fqdn)"
151+
$recordName = $fqdn.split('.',2)[0]
152+
$dnsZone = $fqdn.split('.',2)[1]
153+
New-AzPrivateDnsRecordSet -Name $recordName `
154+
-RecordType A -ZoneName $zoneName `
155+
-ResourceGroupName $ResourceGroupName -Ttl 600 `
156+
-PrivateDnsRecords (New-AzPrivateDnsRecordConfig `
157+
-IPv4Address $ipconfig.properties.privateIPAddress)
158+
}
159+
}
160+
```
161+
127162
### Fetch the private IP addresses
128163

129164
After the private endpoint is provisioned, you can query the IP addresses and the FQDNS mapping by using the following PowerShell script:

0 commit comments

Comments
 (0)