Here, we will see how to automate the creation of azure storage accounts using powershell. We are using Cloud Shell. The intent is to understand the script.
Pre Requisites to create Azure storage accounts
- An Azure account with elevated privileges.
- Install Azure PowerShell Modules from here.
- Otherwise, use Azure CloudShell from Azure Portal.
Script to create multiple azure storage accounts
Let us define the needed variables first.
$resourceGroupName = "AZ-140"
$location = "East US"
Using for loop to create azure storage accounts.
This loop will create 10 similar storage accounts
for ($i = 1; $i -le 10; $i++) {
$storageAccountName = “strgdemoacc$i”
$storageAccount = New-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccountName -Location $location -SkuName Standard_LRS
}
Explanation:
- For loop will do three things. First, it will define all the storage account names here. $storageAccountName = “strgdemoacc$i”
- Second, $storageAccount = New-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccountName -Location $location -SkuName Standard_LRS, this command will create all storage accounts defined in the first bullet.
- Once the loop does its job, it will output a message stating “Created storage account: $storageAccountName” 10 times with the storage account name created.
- This is a basic exercise to create multiple azure storage accounts ,
Output:
