How to create Azure Storage Account using PowerShell

In this article, you will see how to create an Azure Storage Account using PowerShell.


Install the Azure PowerShell Module:

Open Windows PowerShell window and run the below command.


Install-Module -Name Az –AllowClobber

Create Azure Storage Account:

Open a text file. Copy and paste the below 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="psspschennairg"

$storageAccName="psspschennaistorageacc"


## 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

##########################################################################


Open Windows PowerShell window and navigate to the location where the script file was saved.

Run the following command.


.\script.ps1


Result:

Navigate to Azure Portal -> All Resources. New Storage Account created successfully as shown below.



Summary:

Thus in this article you saw how to create an Azure Storage Account using PowerShell.