Windows Azure PowerShell Cmdlets Now Supports Storage!

The Windows Azure Storage team has delivered an outstanding set of PowerShell cmdlets for managing and using storage from PowerShell.

The new abilities include the ability to create and manage containers and blobs which includes the ability to asynchronously copy blobs (across storage accounts and across regions!).

A quick example of how to kick off async blob copies is below. The cmdlets were designed to allow multiple blob copies to start and then to monitor the results at a later time. This allows the end user to take advantage of the async nature of the APIs instead.

 
Import-Module Azure
Select-AzureSubscription mysubscription
 
$destContext = New-AzureStorageContext  –StorageAccountName $storageAccount `
                                        -StorageAccountKey $storageKey
 
New-AzureStorageContainer -Name $containerName
 
$blob1 = Start-CopyAzureStorageBlob -srcUri $srcUri1 `
                                 -DestContainer $containerName `
                                 -DestBlob $fileName1 `
                                 -DestContext $destContext 
 
$blob2 = Start-CopyAzureStorageBlob -srcUri $srcUri2 `
                                 -DestContainer $containerName `
                                 -DestBlob $fileName2 `
                                 -DestContext $destContext 
 
$blob3 = Start-CopyAzureStorageBlob -srcUri $srcUri3 `
                                 -DestContainer $containerName `
                                 -DestBlob $fileName3  `
                                 -DestContext $destContext 
 
$blob1 | Get-AzureStorageBlobCopyState 
$blob2 | Get-AzureStorageBlobCopyState
$blob3 | Get-AzureStorageBlobCopyState

The output of the Get-AzureStorageBlobCopyState cmdlet is below:

CopyId            : 60a3c559-14f4-4b37-ae2b-80755fc072c4
CompletionTime    : 3/27/2013 10:33:29 PM +00:00
Status            : Success
Source            : https://mwweststorage.blob.core.windows.net/source/testcopy1.vhd
BytesCopied       : 32212255232
TotalBytes        : 32212255232
StatusDescription : 

CopyId            : 0c665b44-aa33-47db-8367-b00aa450ed78
CompletionTime    : 3/27/2013 10:33:30 PM +00:00
Status            : Success
Source            : https://mwweststorage.blob.core.windows.net/source/testcopy2.vhd
BytesCopied       : 32212255232
TotalBytes        : 32212255232
StatusDescription : 

CopyId            : d425fae7-c9ba-4816-a81e-d0ded84baa75
CompletionTime    : 3/27/2013 10:33:31 PM +00:00
Status            : Success
Source            : https://mwweststorage.blob.core.windows.net/source/testcopy3.vhd
BytesCopied       : 32212255232
TotalBytes        : 32212255232
StatusDescription : 

The complete list of storage cmdlets are below:

  • Get-AzureStorageContainerAcl
  • Get-AzureStorageBlob
  • Get-AzureStorageBlobContent
  • Get-AzureStorageBlobCopyState
  • Get-AzureStorageContainer
  • New-AzureStorageContainer
  • New-AzureStorageContext
  • Remove-AzureStorageBlob
  • Remove-AzureStorageContainer
  • Set-AzureStorageBlobContent
  • Set-AzureStorageContainerAcl
  • Start-CopyAzureStorageBlob <- will likely be renamed to Start-AzureStorageBlobCopy
  • Stop-CopyAzureStorageBlob <- will likely be renamed to Stop-AzureStorageBlobCopy

6 thoughts on “Windows Azure PowerShell Cmdlets Now Supports Storage!

  1. Nik

    Michael,
    It appears that the ability to asynchronously copy blobs is client side – i.e. the blob is downloaded to the client machine and re-uploaded to the destination machine. Is this correct or am I missing something? Does Windows Azure plan on supporting a web service that will do the copy more efficiently between data-centers and subscriptions.
    Also any plans to support copying across subscriptions? We have staging and production deployments in different subscriptions and would like to be able to move (copy) the staging deployment to the production subscription with an x-copy like mechanism.

    Reply
    1. Michael Washam

      Hi Nik,

      The async blob copy is server side. The Windows Azure Storage Service will reach out and copy from your source to the destination. No client side download required :)

      Reply
  2. Nik

    Turns out, I might have been wrong – http://blogs.msdn.com/b/windowsazurestorage/archive/2012/06/12/introducing-asynchronous-cross-account-copy-blob.aspx
    However we are still having issues getting it to work across accounts through the commandlets. We get the following error message
    “The remote server returned an error: (400) Bad Request. HTTP Status Code: 400 – HTTP Error Message: The copy source account and destination account must be the same.”

    Could you post a sample demonstrating cross account copying using the commandlets. That would help immensely.

    Reply
    1. Yao

      Hi Nik,

      The sample script is shown as below.

      #storage account 1
      $context1 = new-azurestoragecontext -storageaccountname $name1 -storageaccountkey $key1
      #storage account 2
      $context2 = new-azurestoragecontext -storageaccountname $name2 -storageaccountkey $key2

      Start-AzureStorageBlobCopy -SrcContainer $srcContainerName -SrcBlob $srcBlobName -SrcContext $context1 -DestContainer $destContainerName -DestBlob $destBlobName -DestContext $context2

      And you can also use Get-AzureStorageBlobCopyState and Stop-AzureStorageBlobCopy to monitor/stop the copy progress.

      Reply
  3. Nik

    Late post no doubt, but hopefully it helps others. The issue is that the destination storage account was created before June 7th 2012.
    http://msdn.microsoft.com/en-us/library/windowsazure/dd894037.aspx
    As the following MSDN article indicates “Only storage accounts created on or after June 7th, 2012 allow the Copy Blob operation to copy from another storage account.”

    This is rather unfortunate for early adopters of Windows Azure who have storage assets in accounts created before that date.

    Any plans of enabling this API support for older storage accounts?

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>