Using Azure Storage with Powershell – Initial computer setup


To be able to use Powershell to run commands, lookup file and container (folder ) lists, transfer files from your computer to your Azure storage account, you need some initial setup. This is a one time setup that uses certificates for authentication.

Azure Powershell cmdlets are part of the Azure PS module. Follow this link to get it.

Before this initial setup, if you try to use the Azure cmdlets like:

Get-AzureStorageAccount

You’ll get an error similar to:

Get-AzureStorageAccount : No current subscription has been designated. Use Select-AzureSubscription
-Current <subscriptionName> to set the current subscription.
At line:1 char:1
+ Get-AzureStorageAccount
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-AzureStorageAccount], Exception
+ FullyQualifiedErrorId : System.Exception,Microsoft.WindowsAzure.Commands.ServiceManagement.Stor
ageServices.GetAzureStorageAccountCommand

blob5

To get started, we need a certificate. A self signed certificate is OK.

  1. Follow this link to download and install SDK for Windows 8. We need this SDK because it contains the makecert.exe tool that we’ll use in the next step. Alternatively, you can make and export a certificate manually in certmgr.msc
  2. Use makecert.exe tool and the following Powershell commands to create a certificate. Change the first line to reflect the certificate name of your choice:
    $certName = “SamAzure1”
    $makecertPath = “C:\Program Files (x86)\Windows Kits\8.0\bin\x64”
    Set-Location $makecertPath
    .\makecert.exe -sky exchange -r -n “CN=$certName” -pe -a sha1 -len 2048 -ss My “$certName.cer” 
  3. Next, upload the resulting .cer file to your Azure account. In Azure Management Interface, click settings on the bottom left, Management Certificates tab, Upload a management certificate:
    blob4Browse to “C:\Program Files (x86)\Windows Kits\8.0\bin\x64” folder, and the .cer file created in step 2 above. It will be named after the $certName value above.
  4. Next, get your subscription name and ID, under settings:
    blob6

  5. Finally, run the following Powershell commands:
    $certName = “SamAzure1”
    $SubscriptionID = “91e711e4-1620-4e5b-a64b-92a190101010”
    $SubscriptionName = “Visual Studio Premium with MSDN”
    $Cert = Get-ChildItem -Path Cert:\CurrentUser\My | Where { $_.Subject -like “CN=$certName” }
    Set-AzureSubscription -SubscriptionName $SubscriptionName -SubscriptionId $SubscriptionID -Certificate $Cert
    Change the first 3 lines to match your subscription details. $certName must be the same name from step 2 above.

You’re done. This setup remains valid as long as your subscription is active and you haven;t deleted the certificate from your Azure account.

To test, run cmdlets like:

Get-AzureStorageAccount
Get-AzureSubscription
Get-AzureVMImage

 

3 responses

  1. Pingback: Resuming timed out uploads/downloads to/from Azure blob storage with azCopy | Sam's Corner

  2. FYI, I also found this way to get past the error which didnt involved installing the SDK or working with Certs. http://itfreesupport.com/2015/01/azure-powershell-error-no-current-subscription-has-been-designated-use-select-azuresubscription-current-to-set-the-current-subscription/

    Cheers!

    February 15, 2015 at 9:56 am

    • Right Brian, I believe this option was added after this post was written back in September 2014. Changes to Azure are proceeding very rapidly, and getting easier to use every day. I find myself revisiting a lot of the posts and updating the information to reflect current Azure features..

      February 17, 2015 at 3:52 pm

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.