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