Introduction
In this blog, you will see how to create an Azure Storage Account using PowerShell.
Prerequisites
Install Azure PowerShell Module to run the script.
PowerShell Script
Open Notepad and paste the following script. Save the file as script.ps1.
- ################# Azure Blob Storage - PowerShell ####################
-
- ## Input Parameters
- $location="eastus" ## Get all the locations for your Azure Subscription: Get-AzLocation | select Location
- $resourceGroupName="azpractice"
- $storageAccName="azstorageacc1132020"
-
- ## Connect to Azure Account
- Connect-AzAccount
-
- ## Function to create Azure Storage Account
- Function CreateAzStorageAcc
- {
- ## Check if resource group exists
- if(Get-AzResourceGroup -Name $resourceGroupName -ErrorAction SilentlyContinue)
- {
- Write-Host -ForegroundColor Magenta $resourceGroupName "- resource group already exists."
- }
- else
- {
- Write-Host -ForegroundColor Magenta $resourceGroupName "- resource group does not exist."
- Write-Host -ForegroundColor Green "Creating th resource group - " $resourceGroupName
-
- ## Create a new resource group
- New-AzResourceGroup -Name $resourceGroupName -Location $location
- }
-
- ## Check if storage account exists
- if(Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccName -ErrorAction SilentlyContinue)
- {
- Write-Host -ForegroundColor Magenta $storageAccName "- storage account already exists."
- }
- else
- {
- Write-Host -ForegroundColor Magenta $storageAccName "- storage account does not exist."
- Write-Host -ForegroundColor Green "Creating the storage account - " $storageAccName
-
- ## Create a new Azure Storage Account
- New-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccName -Location $location -SkuName Standard_LRS
- }
- }
-
- CreateAzStorageAcc
-
- ## Disconnect from Azure Account
- Disconnect-AzAccount
Open the Windows PowerShell window and navigate to the location where the script file was saved.
Run the following command.
.\script.ps1
Result
Azure Storage Account created successfully.
Summary
Thus, in this blog, you saw how to create an Azure Storage Account using PowerShell.