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.

  1. ################# Azure Blob Storage - PowerShell ####################
  2. ## Input Parameters
  3. $resourceGroupName="azpractice"
  4. $storageAccName="azstorageacc1122020"
  5. $storageContainerName="container001"
  6. $fileName="testdoc"
  7. $filePath=".\testdoc.docx"
  8. ## Connect to Azure Account
  9. Connect-AzAccount
  10. ## Function to upload blob contents
  11. Function UploadBlobContent
  12. {
  13. Write-Host -ForegroundColor Green "Uploading blob content.."
  14. ## Get the storage account
  15. $storageAcc=Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccName
  16. ## Get the storage account context
  17. $ctx=$storageAcc.Context
  18. ## Upload a file
  19. Set-AzStorageBlobContent -Container $storageContainerName -File $filePath -Blob $fileName -Context $ctx -Force
  20. }
  21. UploadBlobContent
  22. ## Disconnect from Azure Account
  23. 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.