Azure PowerShell: Copy Storage Blobs to Local Disk

Here’s how you can copy a set of storage blobs from an Azure storage account container to your local disk. This script assumes you have already logged in to Azure and set your subscription context.

$TargetDirectory = "C:\temp"
$ContainerName = "myContainer"
$StorageResourceGroupName = "MyStorageResourceGroup"
$StorageAccountName = "mystorageaccount"
$StorageAccountKey = (Get-AzureRmStorageAccountKey -ResourceGroupName $StorageResourceGroupName -Name $StorageAccountName)[0].Value
$StorageContext = New-AzureStorageContext –StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey
$StorageBlobs = Get-AzureStorageBlob -Context $StorageContext -Container $ContainerName
ForEach($StorageBlob in $StorageBlobs)
  $BlobName = $StorageBlob.Name  
  Write-Output "Copying $BlobName"
  Get-AzureStorageBlobContent -Blob $BlobName -Container $ContainerName -Destination $TargetDirectory -Context $StorageContext
  Write-Output "Done copying $BlobName"
Write-Output "Done copying."

An optimization would be to use a PowerShell workflow to run the copy in parallel 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 *