How to Create a File Share in an Azure Storage Account using PowerShell

Introduction 

In this blog, you will see how to create a file share in 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.

  1. ################# Azure Blob Storage - PowerShell ####################  
  2.  
  3. ## Input Parameters  
  4. $resourceGroupName="azpractice"  
  5. $storageAccName="azstorageacc1122020"  
  6. $fileShareName="azevents2020"  
  7.  
  8. ## Connect to Azure Account  
  9. Connect-AzAccount   
  10.  
  11. ## Function to get all the blobs  
  12. Function CreateFileShare  
  13. {  
  14.     Write-Host -ForegroundColor Green "Creating an file Share.."    
  15.     ## Get the storage account context  
  16.     $ctx=(Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccName).Context  
  17.     ## Creates an file share  
  18.     New-AzStorageShare -Context $ctx -Name $fileShareName  
  19. }  
  20.   
  21. CreateFileShare   
  22.  
  23. ## Disconnect from Azure Account  
  24. 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

 
Reference

https://docs.microsoft.com/en-us/powershell/module/az.storage/new-azstorageshare?view=azps-3.3.0

Summary

In this blog, you saw how to create a file share in Azure Storage Account using PowerShell.