This is the full example for Adding a new Azure Container with PowerShell.

Read the full post about all the Azure features here.

## Get Parameters
Param(
[string] $ResourceGroupName,
[string] $StorageAccountName,
[string] $StorageContainerName
)

## Static Parameters
#Login-AzureRmAccount
#Set-AzureRmContext -SubscriptionID 11111111-1111-1111-1111-111111111111
#$ResourceGroupName = "GroupName"
#$StorageAccountName = "AccountName"
#$StorageContainerName = "ContainerName"

try{

## Get Storage Details
Write-Output ("Get Storage Account $StorageAccountName Keys")
$Keys = Get-AzureRmStorageAccountKey -ResourceGroupName $ResourceGroupName -Name $StorageAccountName;

Write-Output ("Get Storage Account $StorageAccountName Context")
$StorageContext = New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $Keys[0].Value;

## Create Container
if (!(Get-AzureStorageContainer -Context $StorageContext | Where-Object { $_.Name -eq $StorageContainerName })){

Write-Output ("Creating new Container: $StorageContainerName in Storage Account: $StorageAccountName")
New-AzureStorageContainer -Context $StorageContext -Name $StorageContainerName -Permission Container;

}
else {

Write-Warning "Container $StorageContainerName already exists."

}

}catch {

Write-Error "$_.Exception.Message"

}

Advertisements