Happy America Week. Have a Powershell script on me.

*edit-this looked terrible, copied and pasted from my text editor. I used WP to clean it up, but I'm guessing you'll have all kinds of shit in it if you copy and paste. All I can say is Notepad++/TextMate (screw you, Atom, you hipster editor), and make sure your encoding is on ANSI.* ---begin scripty stuff. Copy below, save as a .ps1 file, and run in Azure Powershell--- ### Derived from/inspired by http://michaelwasham.com/windows-azure-powershell-reference-guide/copying-vhds-blobs-between-storage-accounts/, edited by Tyler Bradford, username:tyler emaildomain:nimbusconsult, a .com|mercial TLD 7-2-14### $t = $host.ui.RawUI.ForegroundColor $host.ui.RawUI.ForegroundColor = "DarkGreen" Write-Output "***Azure Powershell Script to move VHD files from one storage account to another***" "" "This script was created 7-2-14 to try to help what really SHOULD be something you can do through the Azure Management Web Portal. All credit should go to Michael Washam http://michaelwasham.com/ who actually wrote the meat of this script here: http://michaelwasham.com/windows-azure-powershell-reference-guide/copying-vhds-blobs-between-storage-accounts/ I just put some prompts and other options." $host.ui.RawUI.ForegroundColor = $t "" "" $azSubscrp = read-host -Prompt ("Set your Azure subscription by entering the alpha-numeric subscription ID") Set-AzureSubscription $azSubscrp ### Source VHD  - authenticated container ### $srcUri = read-host -Prompt ("Enter the URL of the VHD. You can copy this from Dashboard page of the VM in the Azure Mgmt Portal") ### Source Storage Account  ### $srcStorageAccount = read-host -Prompt ("What is the source Storage Account?") $srcStorageKey = read-host -Prompt ("Enter the storage key for the account. You can find this in the bottom menu option `Manage Access Keys` in the AMP") ### Target Storage Account  ### $destStorageAccount = read-host -Prompt ("What is the destination Storage Account?") $destStorageKey = read-host -Prompt ("Enter the storage key for the account. You can find this in the bottom menu option `Manage Access Keys` in the AMP") ### Create the source storage account context ### $srcContext = New-AzureStorageContext -StorageAccountName $srcStorageAccount ` -StorageAccountKey $srcStorageKey ### Create the destination storage account context ### $destContext = New-AzureStorageContext -StorageAccountName $destStorageAccount ` -StorageAccountKey $destStorageKey ### Create the container on the destination ### $title = "New container" $message = "Do you want to create a new container for these vhd files in the destination storage account?" $yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", ` "Create a new container" $no = New-Object System.Management.Automation.Host.ChoiceDescription "&No", ` "Use an existing container" $options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no) $result = $host.ui.PromptForChoice($title, $message, $options, 0) switch ($result) { 0 {$containerName = read-host -Prompt ("Please give the new container a name") New-AzureStorageContainer -Name $containerName -Context $destContext } 1 {$containerName = read-host -Prompt ("What is the existing destination container name?") } } ### Give the new vhd a name ### $destBlob = read-host -Prompt ("What do you want to call the new vhd file?") ### Start the asynchronous copy - specify the source authentication with -SrcContext ### $blob1 = Start-AzureStorageBlobCopy -srcUri $srcUri ` -SrcContext $srcContext ` -DestContainer $containerName ` -DestBlob $destBlob ` -DestContext $destContext ### Retrieve the current status of the copy operation ### $status = $blob1 | Get-AzureStorageBlobCopyState ### Print out status ### $status ### Loop until complete ### While($status.Status -eq "Pending") { $status = $blob1 | Get-AzureStorageBlobCopyState Start-Sleep 10 ### Print out status ### $status } --end--
This entry was posted in Technology!. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.
  • Leitmotifs

  • Golden Oldies