How To Create An Azure Storage Account Using Azure PowerShell

Introduction 

 
You can access all the Azure resources using Azure PowerShell. Azure PowerShell contains the set of modules that provide multiple cmdlets to manage the Azure resources with PowerShell scripts. You can also build automation process using Azure PowerShell scripts.

Prerequisites

Before you begin utilizing PowerShell to oversee the Azure PowerShell, ensure that the Azure PowerShell has been installed. If not installed, here is an article How to install the Azure PowerShell module. You need to do this only once for each computer from which you are running Azure PowerShell commands.

 

Connect to Azure Portal

 

Connect to Azure Portal using Connect-AzureRmAccount cmdlet.
  1. Connect-AzureRmAccount

How To Create an Azure Storage Account Using Azure PowerShell

 

Creating Azure Resource Group

 

Create an Azure Resource Group so that you can deploy, update, and test web apps in a group. Azure Resource Group is a new approach to group a collection of resources that share a unified life cycle. The benefit of using resource groups in Azure is that we can group all resources that belong to one application.

You can create Resource Groups in Azure using New-AzureRmResourceGroup cmdlets. The required parameters are,

  • Name - Specify the name of the resource group.
  • Location - Specify the Azure data center location of the resource group, such as southindia and westus,
    1. $ResourceGroupName="HubflyGroup003"      
    2. $location="southindia"      
    3. New-AzureRmResourceGroup -Name $ResourceGroupName -Location $location    

How To Create an Azure Storage Account Using Azure PowerShell

Now, check your Azure portal the resource group will be created

How To Create an Azure Storage Account Using Azure PowerShell

Creating an Azure Storage Account

 

Create an Azure storage account using New-AzureRmStorageAccount cmdlet. The required parameters are,

  • AccountName - Specify the name of the storage account.
  • ResourceGroupName - Specify the name of the resource group.
  • Location - Specify the Azure data center location of the resource group, such as South India and West US.
  1. $storageAccoutName = "hubflystorageyyyyyyy"  
  2.   
  3. $skuName = "Standard_LRS"    
  4. New-AzureRmStorageAccount -ResourceGroupName $ResourceGroupName -AccountName $storageAccoutName -Location $location -SkuName $skuName  

How To Create an Azure Storage Account Using Azure PowerShell 

Now, check your Azure portal, hubflystorageyyyyyyy is now created.

How To Create an Azure Storage Account Using Azure PowerShell

Full source code 

  1. $storageAccoutName= Read-Host 'Please Enter the Storage account name'  
  2.   
  3. $resourceGroup = Read-Host 'Please Enter the Resource group name'  
  4.   
  5. $location = Read-Host 'Please Enter the Location'  
  6.   
  7. $skuName = "Standard_LRS"  
  8.   
  9.   
  10. $ctx = Connect-AzureRmAccount 
  11.   
  12. if ($ctx -ne $null)  
  13. {  
  14.     Write-Host ""  
  15.     Write-Host "Please wait your storage account is creating....." -ForegroundColor Cyan  
  16.   
  17.     $storageAccount = New-AzureRmStorageAccount -ResourceGroupName $resourceGroup  -AccountName $storageAccoutName  -Location $location -SkuName $skuName  
  18.   
  19.     if ($storageAccount -ne $null)  
  20.     {  
  21.         Write-Host ""  
  22.         Write-Host "Storage Account Created Sucessfully!" -ForegroundColor Green  
  23.     }  
  24.     else  
  25.     {  
  26.             Write-Host ""  
  27.             Write-Host "Failed to create a storage account" -ForegroundColor Red  
  28.     }  
  29. }  
  30. else  
  31. {  
  32.         Write-Host ""  
  33.         Write-Host "Invalid credentials" -ForegroundColor Red  
  34. }  

That's it. I hope you have learned how to create an Azure Storage Account using Azure PowerShell programmatically. Feel free to fill up the comment box below if you need any assistance.


Similar Articles