Created
May 2, 2017 08:36
-
-
Save astaykov/28024a5052b3e00298c182fd551d4813 to your computer and use it in GitHub Desktop.
Copy VHDs for VMs in Microsoft Cloud Deutschalnd to any other Azure location
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] $destinationUri = "https://[YOUR STORAGE ACCOUNT NAME].blob.core.windows.net/vhds", | |
[String] $destinationKey = "[YOUR STORAGE ACCOUNT KEY]", | |
[String] $sourceAccountPattern = "*disk*", | |
[String] $pathToAzCopy = "C:\Program Files (x86)\Microsoft SDKs\Azure\AzCopy\AzCopy.exe" | |
) | |
clear | |
Login-AzureRmAccount -EnvironmentName AzureGermanCloud | |
$storageAccounts = Get-AzureRmStorageAccount | |
foreach($acct in $storageAccounts) | |
{ | |
Write-Debug "$($acct.StorageAccountName) | $($acct.ResourceGroupName) | $($acct.Location)" | |
if($acct.StorageAccountName -like $sourceAccountPattern) | |
{ | |
$aKey = Get-AzureRmStorageAccountKey -ResourceGroupName $acct.ResourceGroupName -Name $acct.StorageAccountName | |
$primaryKey = $aKey[0].Value | |
$connString = "DefaultEndpointsProtocol=https;AccountName=$($acct.StorageAccountName);AccountKey=$($primaryKey);EndpointSuffix=core.cloudapi.de"; | |
#$connString = "DefaultEndpointsProtocol=https;AccountName=$($acct.StorageAccountName);AccountKey=$($primaryKey)"; | |
$ctx = New-AzureStorageContext -ConnectionString $connString | |
$containers = Get-AzureStorageContainer -Context $ctx | |
foreach($container in $containers) | |
{ | |
Write-Debug $container.Name | |
Write-Debug "===========================================" | |
$blobs = Get-AzureStorageBlob -Container $container.Name -Context $ctx | |
foreach($blob in $blobs) | |
{ | |
if($blob.BlobType -eq "PageBlob" -and $blob.Name -like '*.vhd') | |
{ | |
Write-Debug "$($blob.BlobType) | $($blob.Name) ($($blob.Length))" | |
Write-Debug $blob.ICloudBlob.Container.Uri.AbsoluteUri | |
$cmd = """$($pathToAzCopy)"" /Source:$($blob.ICloudBlob.Container.Uri.AbsoluteUri) /Dest:$($destinationUri) /SourceKey:$($primaryKey) /DestKey:$($destinationKey) /Pattern:$($blob.Name)" | |
Write-Output $cmd | |
$src = $blob.ICloudBlob.Container.Uri.AbsoluteUri | |
$file = $blob.Name | |
& "$pathToAzCopy" /Y /V:"c:\tmp\azcopy.log" /Source:""$src"" /Dest:""$destinationUri"" /SourceKey:""$primaryKey"" /DestKey:""$destinationKey"" /Pattern:""$file"" | |
#& $cmd | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment