PowerShell: Azure Traffic Manager Profiles with Endpoint details


Here is a PowerShell snippet to query Azure Traffic Managers with endpoint details. The script uses PowerShell Az modules so that it is compatible with both Standard PowerShell and PowerShell Core.
The script uses the Azure Resource Graph query to get the resource details.

$trafficManagerQuery = "where type =~ 'microsoft.network/trafficmanagerprofiles'"
$trafficeManagers = Search-AzGraph -Query $trafficManagerQuery

$resultTM = @()
foreach($tm in $trafficeManagers)
{
    $endPoints = $tm.properties.endpoints
    foreach($endPoint in $endPoints)
    {
        $edTagetQuery = "where id =~ '{0}'" -f $endPoint.properties.targetResourceId
        $endTarget = Search-AzGraph -Query $edTagetQuery
        $customObjProperties = [ordered]@{
            'Name' = $tm.name
            'Status' = $tm.properties.profileStatus
            'RoutingMethod' = $tm.properties.trafficRoutingMethod
            'DNSName' = $tm.properties.dnsConfig.fqdn
            'EndPointTarget' = $endPoint.properties.target
            'EndPointStatus' = $endPoint.properties.endpointStatus
            'EndPoinTargetResource' = `
$endTarget.Properties.ipConfiguration.id.split('/')[-4,-1] -join '/'
        }
        $customObjTM = New-Object -TypeName psobject -Property $customObjProperties
        $resultTM += $customObjTM
    }
}

$resultTM

Comments

Popular posts from this blog

Check SQL Server Database Status

PowerShell and Azure Resource Graph

Static Code Analysis: Some Tools