Cloud Skills Blog

Closing the Skills Gap One Student at a Time

Getting Started with Azure PowerShell (Classic)

Want to learn more about Azure PowerShell?

Start a FREE 7 Day Trial and Take one or both of Opsgility’s on-demand courses:

Download the Azure PowerShell Cmdlets

The Azure PowerShell cmdlets can be downloaded from the following link:

Configure your Azure Subscription with the Azure PowerShell Cmdlets.

Option 1: Use Azure AD

The simplest way to access your Azure subscription from PowerShell is to use the Add-AzureAccount cmdlet.


After executing the cmdlet a dialog will appear to prompt you to login with your Microsoft or Organization account. After you login, you will have access for 12 hours before you have to login again.

Option 2: Using a publish settings file.

Running the following code:


Will launch IE and take you to a page where you can login using the Microsoft account associated with your Windows Azure account. Once logged in you will be prompted to download a <subscription-name(s)>.publishsettings file to your hard drive. This page will automatically generate a management certificate in each and every subscription that you are admin or co-administrator of.

TIP: You can change the subscription names in the XML before importing if you want to change the names (you can change them in Windows Azure too). Once the file is downloaded you can then call:

Import-AzurePublishSettingsFile "C:\MyPublishSettings\mysubscriptions.publishsettings"

This cmdlet will install the certificate into your certificate store and configure your subscription settings for PowerShell.

To see the created / stored settings you can browse to the following directory on your machine:
C:\Users\[username]\AppData\Roaming\Windows Azure Powershell

Option 3: Manually configuring a subscription

If you want fine grained control over what certificate setting you use you can also manually specify the certificate.

To do this you will need to create a management certificate using makecert.exe or another tool and then upload that certificate through the Windows Azure Management Portal. Click here fFor more information on managing management certs.

Once your certificate is created and installed in the Windows Azure Portal you can use the following code to configure your subscription:

 $cert = Get-Item Cert:\CurrentUser\My\023875522F55EA7900783BEB7786FB80CA093A25
 Set-AzureSubscription -SubscriptionName "mysub" -SubscriptionId "subscriptionid" -Certificate $cert

Enumerating and selecting a subscription

You can use the PowerShell cmdlets to enumerate and view your current subscription settings.
Here are some of the more handy ones to know about:

# Enumerates all configured subscriptions on your local machine.
 # Returns details only on the specified subscription
Get-AzureSubscription -SubscriptionName "mysubscription" 
# Select the subscription to use
Select-AzureSubscription -SubscriptionName "mysubscription"  
# Sets the mysub subscription to be the default if one is not selected.
Set-AzureSubscription -DefaultSubscription "mysub"

Configuring Storage with the CurrentStorageAccount Parameter

When using the WA Cmdlets with Virtual Machines (IaaS) or Cloud Services (PaaS) you will need to specify the CurrentStorageAccount for your subscription. This is basically the storage account that will be used for creating VHDs or uploading .cspkg files. For virtual machines this storage account has to be in the same datacenter that you plan on creating virtual machines in.

Set-AzureSubscription -SubscriptionName "mysub" -CurrentStorageAccount "mystorageaccount"

Tip: This implies you have a storage account of course.

To discover if you have a storage account or create a new storage account from PowerShell:

# Discover whether you have a storage account already
# Creates a new storage account in the West US data center
New-AzureStorageAcount -StorageAccountName "mystorageaccountname" -Location "West US"

Which of course begs the question – how do I know which data centers are available?

The following cmdlet will give you that information:


This is everything you need to configure the Azure PowerShell cmdlets for your subscription!

leave a reply

Share this page


Connect with Opsgility

Microsoft #AzureStack sparks a jump in private and #hybridcloud spending globally in 2018: via @Forbes

How @Microsoft is extending Its #cloud to #Chevron’s oil fields: @datacenter

Load More...