Vijai Anand Ramalingam

Jan 27, 20191 min

How to upload blob contents in Azure Storage Account using PowerShell

Updated: Mar 14, 2023

In this article, you will see how to upload blob contents in Azure Storage Account using PowerShell.

Install the Azure PowerShell Module:

Open Windows PowerShell window and run the below command.

Install-Module -Name Az –AllowClobber

Download Blob Contents:

Open a text file. Copy and paste the below script. Save the file as script.ps1.

################# Azure Blob Storage - PowerShell ####################

## Input Parameters

$resourceGroupName="psspschennairg"

$storageAccName="psspschennaistorageacc"

$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 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 as shown below.

Summary:

Thus in this article you saw how to upload blob contents in Azure Storage Account using PowerShell.

    0