Introduction
In this blog, you will see how to upload files to Azure 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"
- $fileName="testdoc.docx"
- $folderPath="/"
- ## Connect to Azure Account
- Connect-AzAccount
- ## Function upload files to file share
- Function UploadFiles
- {
- Write-Host -ForegroundColor Green "Upload files to file share.."
- ## Get the storage account context
- $ctx=(Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccName).Context
- ## Get the file share
- $fileShare=Get-AZStorageShare -Context $ctx -Name $fileShareName
- ## Upload the file
- Set-AzStorageFileContent -Share $fileShare -Source $fileName -Path $folderPath -Force
- }
- UploadFiles
- ## 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
Reference
Summary
In this blog, you saw how to upload files to Azure File Share using PowerShell.

Dhanya GopinathPosted Nov 22, 2022, 11:50 PM
I am following your tutorial. Very nicely explained. When I executed, I got one errorSet-AzStorageFileContent -Share $fileShare -Source $fileName -Pat … | ~~~~~~~~~~ | Cannot bind parameter 'Share'. Cannot convert the "Microsoft.WindowsAzure.Commands.Common.Storage.ResourceModel.AzureStorageFileShare" value of type "Microsoft.WindowsAzure.Commands.Common.Storage.ResourceModel.AzureStorageFileShare" to type "Microsoft.Azure.Storage.File.CloudFileShare". So I changed to Set-AzStorageFileContent -Share $fileShare.CloudFileShare -Source $fileName -Path $folderPath -Force
James FradericPosted Oct 31, 2022, 6:04 PM
HI Vijay, could you please guide me how can we add file with its metadata as well ????