Last active
January 31, 2017 15:59
-
-
Save jeffpatton1971/4e3b2c7a50df24069020ced0b4f04f10 to your computer and use it in GitHub Desktop.
A script to copy Blobs between Azure Storage Accounts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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