Created
November 21, 2020 11:54
-
-
Save stefanstranger/16ab9049ff095279777d7329bd9974a8 to your computer and use it in GitHub Desktop.
Check Azure Container Registry Name
This file contains 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
# Check if the name myRegistry can be used for a new Azure Registry Container. | |
# More info: https://docs.microsoft.com/en-us/rest/api/containerregistry/registries/checknameavailability | |
#region variables | |
$ACRName = 'myRegistry' | |
$ResourceType = 'Microsoft.ContainerRegistry/registries' | |
#endregion | |
#region Get AccessToken | |
$Context = Get-AzContext | |
$azureProfile = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile | |
$profileClient = New-Object -TypeName Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient -ArgumentList ($azureProfile) | |
$token = $profileClient.AcquireAccessToken($Context.Subscription.TenantId) | |
#endregion | |
#region Validate ACR Name | |
$uri = ('https://management.azure.com/subscriptions/{0}/providers/{1}/checkNameAvailability?api-version=2019-05-01' -f $($Context.Subscription.id), $($ResourceType.Split('/')[0])) | |
$params = @{ | |
'Uri' = $uri | |
'ContentType' = 'application/json' | |
'Headers' = @{ | |
'authorization' = "Bearer $($Token.AccessToken)" | |
} | |
'Method' = 'POST' | |
'Body' = @{ | |
'name' = $ACRName | |
'type' = $ResourceType | |
} | ConvertTo-Json | |
} | |
Invoke-RestMethod @params | |
#endregion |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment