How To Upload files to Azure Blob Storage using PowerShell and AzCopy

This post has been republished via RSS; it originally appeared at: New blog articles in Microsoft Tech Community.

Azure Blob Storage is a great place to store files. In this post, I quickly wanted to show you how you can create a simple script to upload files to Azure blob storage using PowerShell and AzCopy. AzCopy is a command-line utility that you can use to copy blobs or files to or from a storage account. It is the recommended option for faster copy operations.

First, make sure you have AzCopy installed. If you didn’t configure the path variable, make sure you run this script from the path where AzCopy is stored. This example uses the SAS token to authenticate against the Azure Storage.


AzCopy Syntax:


azcopy copy SourcePath DestinationURI


AzCopy Example uploading a local image folder an Azure Blob Storage Container using a SAS token.


azcopy copy “C:\temp\images” “" --recursive=true”

With this quick Azure PowerShell script, you can automatically generate the SAS token. If you are running on Linux or macOS, you can simply install the cross-platform PowerShell Core 6 version and the Azure Az PowerShell module.


# Connect to Azure
# List Azure Subscriptions

# Define Variables
$subscriptionId = "yourSubscriptionId"
$storageAccountRG = "demo-azcopy-rg"
$storageAccountName = "tomsaccount"
$storageContainerName = "images"
$localPath = "C:\temp\images"

# Select right Azure Subscription
Select-AzSubscription -SubscriptionId $SubscriptionId

# Get Storage Account Key
$storageAccountKey = (Get-AzStorageAccountKey -ResourceGroupName $storageAccountRG -AccountName $storageAccountName).Value[0]

# Set AzStorageContext
$destinationContext = New-AzStorageContext -StorageAccountName $storageAccountName -StorageAccountKey $storageAccountKey

# Generate SAS URI
$containerSASURI = New-AzStorageContainerSASToken -Context $destinationContext -ExpiryTime(get-date).AddSeconds(3600) -FullUri -Name $storageContainerName -Permission rw

# Upload File using AzCopy
azcopy copy $localPath $containerSASURI –recursive

I hope this helps you to find a quick way to easily upload files to Azure Blob Storage containers. To learn more about how to interact with Azure PowerShell and Azure Blob Storage, check out the Microsoft Docs: Quickstart: Upload, download, and list blobs by using Azure PowerShell

If you have questions, let me know in the comments.

REMEMBER: these articles are REPUBLISHED. Your best bet to get a reply is to follow the link at the top of the post to the ORIGINAL post! BUT you're more than welcome to start discussions here:

This site uses Akismet to reduce spam. Learn how your comment data is processed.