Introduction
In this blog, you will see how to upload blob contents in an Azure Storage Account 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"
- $storageContainerName="container001"
- $fileName="testdoc"
- $filePath=".\testdoc.docx"
-
- ## Connect to Azure Account
- Connect-AzAccount
-
- ## Function to upload blob contents
- Function UploadBlobContent
- {
- Write-Host -ForegroundColor Green "Uploading blob content.."
- ## Get the storage account
- $storageAcc=Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccName
- ## Get the storage account context
- $ctx=$storageAcc.Context
- ## Upload a file
- Set-AzStorageBlobContent -Container $storageContainerName -File $filePath -Blob $fileName -Context $ctx -Force
- }
-
- UploadBlobContent
-
- ## 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:
Blob contents uploaded successfully.
Reference:
https://docs.microsoft.com/en-us/powershell/module/az.storage/set-azstorageblobcontent?view=azps-3.3.0
Summary:
In this blog, you saw how to upload blob contents in Azure Storage Account using PowerShell.