Wednesday, November 21, 2012

Accessing Windows Azure blob storage

I have some files transferred to a container in my storage account. Now on a new VM, I need to access these files, but do not have CloudXplorer since .NET has not yet been installed. So I turned to the StorageClient module and Powershell.

Import-Module Microsoft.WindowsAzure.StorageClient.dll
$storageAccountName = 'my storage account'
$accessKey = 'my access key'
$storageCredentials = New-Object Microsoft.WindowsAzure.StorageCredentialsAccountAndKey($storageAccountName, $accessKey)
$storageAccountEndpoint = "http://$storageAccountName.blob.core.windows.net/"
$blobClient = New-Object Microsoft.WindowsAzure.StorageClient.CloudBlobClient($storageAccountEndpoint, $storageCredentials)
$filename = "my file"
$blob = $blobClient.GetBlobReference($filename)
$localFilename = "local filename"
$blob.DownloadToFile($localFilename)

References:
CloudBlob.DownloadToFile
Microsoft.WindowsAzure.StorageClient


Edit 2013-04-05
This is based on the 1.0 Storage Client. Updated script can be found in an updated post on Windows Azure Storage through Powershell

No comments:

Post a Comment