Skip to content

Instantly share code, notes, and snippets.

@ivansharamok
Created September 26, 2017 01:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivansharamok/15692dcfb9ed03552d9e0ebb30d089ca to your computer and use it in GitHub Desktop.
Save ivansharamok/15692dcfb9ed03552d9e0ebb30d089ca to your computer and use it in GitHub Desktop.
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