Azure PowerShell: Copy Local File to Blob Storage

Here’s a simple script that copies a local file to Azure blob storage:

$ResourceGroupName = "MyResourceGroup"
$StorageAccountName = "mysstorageaccount"
$File = "C:\TestExtension.ps1"
$Container = "extensions"
$Blob = "test\TestExtension.ps1"
 
$StorageAccountKey = (Get-AzureRmStorageAccountKey -ResourceGroupName $ResourceGroupName -Name $StorageAccountName)[0].Value
$StorageContext = New-AzureStorageContext –StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey
Set-AzureStorageBlobContent -File $File -Container $Container -Blob $Blob -Context $StorageContext

The script assumes you have already logged in and set your subscription context.

A parallelized, multi-file version can be found in the azure-sdk-tools-samples on GitHub:
https://github.com/Azure/azure-sdk-tools-samples/blob/master/solutions/data-management/CopyFilesToAzureStorageContainer.ps1.

Hope this helps.

This entry was posted in Azure, PowerShell. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *