Introduction

In this blog, you will see how to create a directory in file share 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. ## Input Parameters
  3. $resourceGroupName="azpractice"
  4. $storageAccName="azstorageacc1122020"
  5. $fileShareName="azevents2020"
  6. $directoryPath="Presentation"
  7. ## Connect to Azure Account
  8. Connect-AzAccount
  9. ## Function to create directory
  10. Function CreateDirectory
  11. {
  12. Write-Host -ForegroundColor Green "Creating directory in file share.."
  13. ## Get the storage account context
  14. $ctx=(Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccName).Context
  15. ## Create directory
  16. Get-AzStorageShare -Context $ctx -Name $fileShareName | New-AzStorageDirectory -Path $directoryPath
  17. }
  18. CreateDirectory
  19. ## Disconnect from Azure Account
  20. 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-azstoragedirectory?view=azps-3.3.0

Summary

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