Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A script to copy Blobs between Azure Storage Accounts
param
(
[string]$SourceStorageAccountName,
[string]$SourceStorageAccountResourcegroupName,
[string]$SourceStorageAccountContainerName,
[string]$DestStorageAccountKey,
[string]$DestStorageAccountContainerName
)
try
{
$ErrorActionPreference = 'stop';
$Error.Clear();
#
# Setup source storage account and container
#
$SourceStorageAccount = Get-AzureRmStorageAccount -ResourceGroupName $SourceStorageAccountResourcegroupName -Name $SourceStorageAccountName;
$SourceStorageAccountContainer = Get-AzureStorageContainer -Name $SourceStorageAccountContainerName -Context $SourceStorageAccount.Context;
#
# Setup destination context and container
#
$DestContext = New-AzureStorageContext -StorageAccountName $DestStorageAccountContainerName -StorageAccountKey $DestStorageAccountKey;
$DestStorageAccountContainer = Get-AzureStorageContainer -Name $DestStorageAccountContainerName -Context $DestContext;
#
# Get a list of blobs to copy
#
Get-AzureStorageBlob -Container $SourceStorageAccountContainer.Name -Context $SourceStorageAccount.Context |
ForEach-Object {
#
# copy each blob
#
$DestBlob = $_.Name;
$SrcURI = $_.ICloudBlob.StorageUri.PrimaryUri.AbsoluteUri;
Start-AzureStorageBlobCopy -Context $SourceStorageAccount.Context -SrcUri $SrcURI -DestContext $DestContext -DestContainer $DestStorageAccountContainerName -DestBlob $DestBlob -Force;
}
}
catch
{
throw $_;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.