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.
- ################# Azure Blob Storage - PowerShell ####################
- ## Input Parameters
- $resourceGroupName="azpractice"
- $storageAccName="azstorageacc1122020"
- $fileShareName="azevents2020"
- $directoryPath="Presentation"
- ## Connect to Azure Account
- Connect-AzAccount
- ## Function to create directory
- Function CreateDirectory
- {
- Write-Host -ForegroundColor Green "Creating directory in file share.."
- ## Get the storage account context
- $ctx=(Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccName).Context
- ## Create directory
- Get-AzStorageShare -Context $ctx -Name $fileShareName | New-AzStorageDirectory -Path $directoryPath
- }
- CreateDirectory
- ## Disconnect from Azure Account
- Disconnect-AzAccount
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.

Edis HodzicPosted Oct 18, 2022, 7:15 PM
If you want to create one subfolder here as well, or more, you can use this (1 subfolder e.g ): $resourceGroupName="azpractice" $storageAccName="azstorageacc1122020" $fileShareName="azevents2020" $directoryPath="Presentation" ## Connect to Azure Account Connect-AzAccount ## Function to create directory Function CreateDirectory { Write-Host -ForegroundColor Green "Creating directory in file share.." ## Get the storage account context $ctx=(Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccName).Context ## Create directory Get-AzStorageShare -Context $ctx -Name $fileShareName | New-AzStorageDirectory -Path $directoryPath } CreateDirectory ## Connect to Azure Account Connect-AzAccount ## Function to create directory Function CreateDirectory { Write-Host -ForegroundColor Green "Creating directory in file share.." ## Get the storage account context $ctx=(Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccName).Context ## Create directory Get-AzStorageShare -Context $ctx -Name $fileShareName | New-AzStorageDirectory -Path $directoryPath Get-AzStorageShare -Context $ctx -Name $fileShareName | New-AzStorageDirectory -Path $directoryFolder } CreateDirectory ## Disconnect from Azure Account Disconnect-AzAccount