skip to Main Content
Connect-AzAccount -Tenant 'xxxxx' -SubscriptionId 'xxxx'

# Get the Resource Group Name
$resourceGroupName = "city-app-rg-xx-uat"

# Get all Private Endpoints in the Resource Group
$privateEndpoints = Get-AzPrivateEndpoint -ResourceGroupName $resourceGroupName

# Create a list to store the data
$data = @()

# Loop through each Private Endpoint
foreach ($privateEndpoint in $privateEndpoints) {
    $fqdn = $privateEndpoint.PrivateDnsZoneGroup.Name
    $ipAddresses = $privateEndpoint.PrivateIPAddresses -join ","
    $name = $privateEndpoint.Name

    $data += [PSCustomObject]@{
        FQDN = $fqdn
        IPAddress = $ipAddresses
        Name = $name
    }
}

# Export the data to a CSV file
$data | Export-Csv -Path "PrivateEndpointDetails.csv" -NoTypeInformation

Output received:

enter image description here

In the output, the Fully Qualified Domain Name (Private endpoint URL) and the Private IPs of the azure resources are not printed in the output file.

Unable to identify what is wrong in the above PowerShell script.

2

Answers


  1. I might not have exactly what your looking for but you can use this to get the information at least, you can then use it to scope it differently for your need 🙂

    # Retrieve all private endpoints in the subscription
    $privateEndpoints = Get-AzPrivateEndpoint
    
    # Check if private endpoints exist
    if ($privateEndpoints.Count -eq 0) {
        Write-Host "No private endpoints found in this subscription."
        exit
    }
    
    # Loop through each private endpoint and output information
    foreach ($endpoint in $privateEndpoints) {
        Write-Output "Resource Group: $($endpoint.ResourceGroupName)"
        Write-Output "Private Endpoint Name: $($endpoint.Name)"
    
        # Initialize an array to store FQDNs
        $fqdnList = @()
        
        # Loop through private link service connections to build FQDNs
        foreach ($connection in $endpoint.PrivateLinkServiceConnections) {
            if ($connection.GroupIds -and $connection.GroupIds.Count -gt 0) {
                foreach ($group in $connection.GroupIds) {
                    $fqdnList += "$($group).privatelink.$($connection.Name).azure.net"
                }
            }
        }
    
        # Display FQDNs or "None found" if empty
        if ($fqdnList.Count -gt 0) {
            Write-Output "FQDNs:"
            foreach ($fqdn in $fqdnList) {
                Write-Output "  - $fqdn"
            }
        } else {
            Write-Output "FQDNs: None found"
        }
    
        # Retrieve the private IP addresses from network interfaces
        Write-Output "IP Addresses:"
        $networkInterface = Get-AzNetworkInterface -ResourceId $endpoint.NetworkInterfaces.Id
    
        # Loop through IP configurations to fetch private IP addresses
        $ipAddresses = $networkInterface.IpConfigurations | ForEach-Object { $_.PrivateIpAddress }
        
        if ($ipAddresses.Count -gt 0) {
            foreach ($ip in $ipAddresses) {
                Write-Output "  - $ip"
            }
        } else {
            Write-Output "  - None found"
        }
    
        Write-Output "-----------------------------------------"
    }
    

    Hope this is helpful and remember shared knowledge is the best knowledge 😊
    Best Regards,
    Timmy Malmgren


    If the Answer is helpful, please click "Accept Answer" and upvote it as it helps others to find what they are looking for faster!

    Login or Signup to reply.
  2. Get Private FQDNs, IPs, Names of the Private Endpoints for the Azure resources deployed in an Virtual Network using PowerShell Script

    Here is the updated PowerShell script to fetch the private endpoint FQDN and Private IP address.

    $dnsConfigData = @()
    
    $privateEndpoints = Get-AzPrivateEndpoint -ResourceGroupName "Automation_RG"
    
    foreach ($endpoint in $privateEndpoints) {
        if ($endpoint.CustomDnsConfigsText) {
            
            $dnsConfigs = $endpoint.CustomDnsConfigsText | ConvertFrom-Json
            foreach ($config in $dnsConfigs) {
               
                $PEfqdn = $config.Fqdn
                $PEipAddresses = $config.IpAddresses -join "," 
    
                
                $dnsConfigData += [pscustomobject]@{
                    Fqdn        =  $PEfqdn
                    IpAddresses = $PEipAddresses
                }
            }
        } else {
            Write-Output "No Custom DNS Configs found for this endpoint."
        }
    }
    $dnsConfigData | Export-Csv -Path "PrivateEndpointDnsdetails.csv" -NoTypeInformation -Encoding UTF8
    
    Write-Output "CSV file created: PrivateEndpointDnsdetails.csv"
    

    Output:

    enter image description here

    Excel Output

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search