Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Create Azure Container Registry via Azure CLI
<#
.Synopsis
Create Azure Container Registry. Requires azure-cli >= 2.0.13
.Example
.\create-acr.ps1 -RegistryName myacr -ResourceGroup sc-acr -Location westus -Sku Basic
.Example
.\create-acr.ps1 -RegistryName myacr -ResourceGroup sc-acr -Location eastus -Sku Managed_Basic
.Example
.\create-acr.ps1 -RegistryName myacr -ResourceGroup sc-acr -Location westcentralus -Sku Managed_Basic
.Example
.\create-acr.ps1 -RegistryName myacr -ResourceGroup sc-acr -Location westcentralus -Sku Managed_Standard -EnableAdmin
#>
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)] $RegistryName,
[Parameter(Mandatory=$true)] $ResourceGroup,
[Parameter(Mandatory=$true)] $Location,
[Parameter(Mandatory=$true)] $Sku,
[Parameter(Mandatory=$false)][switch] $EnableAdmin=$false
)
$Error.Clear()
Trap
{
Write-Error $_.ErrorDetails.Message
Write-Error $_.InvocationInfo.PositionMessage
Write-Error $_.CategoryInfo.ToString()
Write-Error $_.FullyQualifiedErrorId
$e = $_.Exception
while ($e.InnerException) {
$e = $e.InnerException
$msg += "`n" + $e.Message
}
break;
}
$groupExists = az group exists -n $ResourceGroup
if ($groupExists -ne "true"){
$response = Read-Host -Prompt "Group $ResourceGroup does not exist. Do you want to create one? [yes(y)/no(n)]"
if ($response -ieq "yes" -or $response -ieq "y"){
$location = Read-Host "Enter location for resource group (e.g. westus, eastus, etc.)"
az group create -n $ResourceGroup --location $location
}
else{
Write-Host "Must have existing resource group to create ACR. Script terminated." -ForegroundColor Red
exit
}
}
az acr create -n $RegistryName -g $ResourceGroup --location $Location --sku $Sku --admin-enabled $($EnableAdmin.ToString().ToLowerInvariant())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.