Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

The Scary DBA

I have twenty+ years experience in IT. That time was spent in technical support, development and database administration. I work forRed Gate Software as a Product Evangelist. I write articles for publication at SQL Server Central, Simple-Talk, PASS Book Reviews and SQL Server Standard. I have published two books, ”Understanding SQL Server Execution Plans” and “SQL Server 2008 Query Performance Tuning Distilled.” I’m one of the founding officers of the Southern New England SQL Server Users Group and its current president. I also work on part-time, short-term, off-site consulting contracts. In 2009 and 2010 I was awarded as a Microsoft SQL Server MVP. In the past I’ve been called rough, intimidating and scary. To which I usually reply, “Good.” You can contact me through grant -at- scarydba dot kom (unobfuscate as necessary).

Using PowerShell to move files to Azure Storage

I was searching all over the place to try to find out how to move files into Azure Storage. Most of the examples I could track down were for API calls through C#. There were very few examples using PowerShell, and most of those were for older versions of Azure. But, the one thing I’ve learned about Azure, it’s a fast moving target. Sure enough, in March there were new PowerShell blob cmdlets released. This is great news. I was able to get this to work:

[System.Reflection.Assembly]::LoadFrom("C:\Program Files\Microsoft SDKs\Windows Azure\.NET SDK\2012-10\bin\Microsoft.WindowsAzure.StorageClient.dll")

$account = [Microsoft.WindowsAzure.CloudStorageAccount]::Parse("DefaultEndpointsProtocol=https;AccountName=mystorage;AccountKey=mykey")
$client = [Microsoft.WindowsAzure.StorageClient.CloudStorageAccountStorageClientExtensions]::CreateCloudBlobClient($account)
$blob = $client.GetBlockBlob('container\adw.bacpac')
$blob.UploadFile("c:\bu\adw.bacpac")

But let’s face it, this code makes more sense and is a heck of lot easier to write:

$context = New-AzureStorageContext -StorageAccountName mystorage -StorageAccountKey mykey 
Set-AzureStorageBlobContent -Blob "adw.bacpac" -Container container -File "c:\bu\adw.bacpac" -Context $context -Force

The problem is, since the stuff has only been out since March, anyone with working code is likely to be using the first sample. In fact, if you search for New-AzureStorageContext and put it inside quotes so you only get exactly that, you won’t even see the blog from Microsoft that I linked above until the fourth entry, let alone documentation. Heck, if you search MSDN for New-AzureStorageContext there are only two entries. So, I’m getting this blog post out in order to help spread the word. Here’s one other source of information on the new Azure Blob Storage commands in PowerShell from Microsoft

There is excellent stuff coming out from the Azure team in and around PowerShell. If you’re not using PowerShell to automate your local servers, you’re crazy, but the good news is it’s getting easier and easier to administer Azure from PowerShell as well.

Comments

Leave a comment on the original post [www.scarydba.com, opens in a new window]

Loading comments...