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
https://docs.microsoft.com/en-us/powershell/module/az.storage/set-azstoragefilecontent?view=azps-3.3.0
Summary
In this blog, you saw how to upload files to Azure File Share using PowerShell.