azure Azure Powershell Managing Traffic Managers

30% OFF - 9th Anniversary discount on Entity Framework Extensions until December 15 with code: ZZZANNIVERSARY9

Example

With Azure PowerShell you can get certain functionality currently unavailable on Azure Portal, like:

  • Reconfigure all Traffic Manager's endpoints at once
  • Address other services via Azure ResourceId instead of domain name, so you don't need to set Location manually for Azure Endpoints

Prerequisites

To start you need to login and select RM subscription.

Get TrafficManager profile

Operations with Traffic Managers via PowerShell are done in three steps:

  1. Get TM profile:
    $profile = Get-AzureRmTrafficManagerProfile -ResourceGroupName my-resource-group -Name my-traffic-manager
    Or create new as in this article.
  2. Explore and modify TM profile
    Check $profile fields and $profile.Endpoints to see each endpoint's configuration.
  3. Save changes via Set-AzureRmTrafficManagerProfile -TrafficManagerProfile $profile.

Change endpoints

All current endpoints are stored in $profile.Endpoints list, so you can alter them directly by index
$profile.Endpoints[0].Weight = 100
or by name
$profile.Endpoints | ?{ $_.Name -eq 'my-endpoint' } | %{ $_.Weight = 100 }

To clear all endpoints use
$profile.Endpoints.Clear()

To delete particular endpoint use
Remove-AzureRmTrafficManagerEndpointConfig -TrafficManagerProfile $profile -EndpointName 'my-endpoint'

To add new endpoint use
Add-AzureRmTrafficManagerEndpointConfig -TrafficManagerProfile $profile -EndpointName "my-endpoint" -Type AzureEndpoints -TargetResourceId "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/my-resource-group/providers/Microsoft.ClassicCompute/domainNames/my-azure-service" -EndpointStatus Enabled -Weight 100

As you can see, in the last case we've addressed our azure service via ResourceId rather than domain name.

Keep in mind

Your changes to TM and it's endpoints are not applied until you'll invoke Set-AzureRmTrafficManagerProfile -TrafficManagerProfile $profile. That allows you to fully reconfigure TM in one operation.

Traffic Manager is an implementation of DNS and IP address given to clients has some time to live (aka TTL, you can see it's duration in seconds in the $profile.Ttl field). So, after you've reconfigured TM some clients will continue to use old endpoints they cached until that TTL expire.



Got any azure Question?