-2

I'm trying to add a new Traffic Manager endpoint to an existing profile in a powershell script as part of a deployment pipeline. In the Azure portal I'm able to simply add a second endpoint and a new priority is assigned. Since I'm using weighted policy the priority is meaningless for me, so I don't care what it is. I don't want to set it with a random number since that could still fail the job.

The documentation claims that new endpoints should be auto assigned a new value, but this only works if I remove all existing endpoints first then add them all back in. Since the get-AzureRMTrafficManagerEndPoint cmdlet requires the endpoint name (not optional) and I don't know all of the endpoint names I have no way to remove and re-add them.

Am I approaching this wrong? Is it a bug? Am I using the commands wrong?

The error text is "Set-AzureRmTrafficManagerProfile : BadRequest: The endpoint priorities are not set correctly. The priorities must be set on all or none of the endpoints."

This code works:

$TrafficManagerProfile = Get-AzureRmTrafficManagerProfile -Name "TMName" -ResourceGroupName "TMRGName"
$publicIPObj = Get-AzureRmPublicIpAddress -ResourceGroupName "App1RGName"
Add-AzureRmTrafficManagerEndpointConfig -EndpointName "App1" -EndpointStatus Enabled -TargetResourceId $publicIPObj.id -TrafficManagerProfile $TrafficManagerProfile -Type AzureEndpoints -Weight 10
$publicIPObj = Get-AzureRmPublicIpAddress -ResourceGroupName "App2RGName"
Add-AzureRmTrafficManagerEndpointConfig -EndpointName "App2" -EndpointStatus Enabled -TargetResourceId $publicIPObj.id -TrafficManagerProfile $TrafficManagerProfile -Type AzureEndpoints -Weight 10
Set-AzureRmTrafficManagerProfile -TrafficManagerProfile $TrafficManagerProfile

This code fails:

   $TrafficManagerProfile = Get-AzureRmTrafficManagerProfile -Name "TMName" -ResourceGroupName "TMRGName"
    $publicIPObj = Get-AzureRmPublicIpAddress -ResourceGroupName "App1RGName"
    Add-AzureRmTrafficManagerEndpointConfig -EndpointName "App1" -EndpointStatus Enabled -TargetResourceId $publicIPObj.id -TrafficManagerProfile $TrafficManagerProfile -Type AzureEndpoints -Weight 10
    Set-AzureRmTrafficManagerProfile -TrafficManagerProfile $TrafficManagerProfile
    $TrafficManagerProfile = Get-AzureRmTrafficManagerProfile -Name "TMName" -ResourceGroupName "TMRGName"
    $publicIPObj = Get-AzureRmPublicIpAddress -ResourceGroupName "App2RGName"
    Add-AzureRmTrafficManagerEndpointConfig -EndpointName "App2" -EndpointStatus Enabled -TargetResourceId $publicIPObj.id -TrafficManagerProfile $TrafficManagerProfile -Type AzureEndpoints -Weight 10
    Set-AzureRmTrafficManagerProfile -TrafficManagerProfile $TrafficManagerProfile
4

1 回答 1

0

The way your code is working and the extra line of $TrafficManagerProfile = Get-AzureRmTrafficManagerProfile -Name "TMName" -ResourceGroupName "TMRGName" is causing this to fail.

You are adding configuration to the Traffic Manager profile for one endpoint, then trying to set it. You need to modify your code so it's the same as your first sample, the difference there is your grabbing the Traffic Manager profile, adding the endpoints and then calling Set-AzureRmTrafficManagerProfile once, rather than twice in your second example.

Edit: Adding some code to get the endpoints in the profile.

$Profiles = Get-AzureRmTrafficManagerProfile -Name mctmp -ResourceGroupName TM

foreach ($Profile in $Profiles.Endpoints.Name) {
    Get-AzureRmTrafficManagerEndpoint -Name $Profile -ProfileName $Profiles.RelativeDnsName -ResourceGroupName TM -Type ExternalEndpoints
}
于 2016-11-17T10:33:27.590 回答