Created
March 10, 2017 09:17
-
-
Save lawrencegripper/1b073da8c91d5c92e6dca69fa2540ed5 to your computer and use it in GitHub Desktop.
Quick script to update a tm profile, enabling or disabling an endpoint. The script will ensure you never disable all endpoints.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # | |
| # Update_TrafficManagerProfile.ps1 | |
| # | |
| # Example Usage: .\Update-TrafficManagerProfile.ps1 -TMResourceName "lawrence-scratch-www" -ResourceGroup "lawrence-scratch" -ProfileName "example1" -DisableEndpoint | |
| Param( | |
| [string][Parameter(Mandatory=$true)] $TMResourceName, | |
| [string][Parameter(Mandatory=$true)] $ResourceGroup, | |
| [string][Parameter(Mandatory=$true)] $ProfileName, | |
| [switch][parameter(ParameterSetName="enableSet")]$EnableEndpoint, | |
| [switch][parameter(ParameterSetName="disableSet")]$DisableEndpoint | |
| ) | |
| $ErrorActionPreference = "Stop"; | |
| Write-Host "" | |
| Write-Host "Fetching Endpoints on: $TMResourceName" | |
| Write-Host "***************************************" | |
| $profile = Get-AzureRmTrafficManagerProfile –Name $TMResourceName -ResourceGroupName $ResourceGroup | |
| Write-Host "$($profile.Endpoints.Count) endpoints found." | |
| $profile.Endpoints | %{Write-host "-- $($_.Name)"} | |
| Write-Host "" | |
| Write-Host "Updating Endpoint: $ProfileName" | |
| Write-Host "***************************************" | |
| #Get the endpoint we want | |
| $endpointToDisable = $profile.Endpoints | ?{ $_.Name -eq $ProfileName } | select -first 1 | |
| if ($EnableEndpoint) | |
| { | |
| Write-Host "--Enabling Endpoint: $ProfileName" | |
| $endpointToDisable.EndpointStatus = "Enabled" | |
| } | |
| if ($DisableEndpoint) | |
| { | |
| Write-Host "--Disabling Endpoint: $ProfileName" | |
| $endpointToDisable.EndpointStatus = "Disabled" | |
| } | |
| $enabledEndpoints = $profile.Endpoints | ?{ $_.EndpointStatus -eq "Enabled" } | Measure | |
| if ($enabledEndpoints.Count -lt 1) | |
| { | |
| throw "Disabling this endpoint would leave not endpoints enabled and result in an outage!! Aborting!!" | |
| } | |
| #Save the config back to azure | |
| $updatedProfile = Set-AzureRmTrafficManagerProfile –TrafficManagerProfile $profile | |
| Write-Host "" | |
| Write-Host "Update Completed" | |
| Write-Host "***************************************" | |
| $updatedProfile.Endpoints | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment