Create Storage Container with Powershell

This Script will ask login details and then sets the context for your subscription id. Then it tries to retrieve storage account inside given resource group and creates tries to find container inside storage account and if not found then creates it.

Login-AzureRmAccount
Set-AzureRmContext -SubscriptionId "your subcription id"
$ResourceGroupName='test-rg'
$Location='Southeast Asia'
$storageSku = "Standard_LRS";
$StorageAccountName='testsa' #it should be unique
$StorageAccount = Get-AzureRmStorageAccount -ResourceGroupName $ResourceGroupName -Name $StorageAccountName  -ErrorAction Ignore
$containerName='testcontainer'
$container = Get-AzureStorageContainer -Context $StorageAccount.Context -Name $containerName -ErrorAction Ignore
if(($container| Measure-Object).Count -eq 0)
{
   $container = New-AzureStorageContainer -Context $StorageAccount.Context -Name $containerName -Permission 'Off'


}

Comments