Configuring Connectivity with Windows Azure PowerShell Cmdlets

I’ve been noticing an increasing level of confusion about how to set up connectivity between Windows Azure and a person’s machine using the Windows Azure PowerShell cmdlets.  I’d like to try to set a few things straight.

It seems that nearly all the tutorials, examples, and quick starts on using the Windows Azure PowerShell cmdlets start with one command:

Get-AzurePublishSettingsFile

I view this is a convenience command.  Executing the command will do the following:

  1. Opens a browser window to https://windows.azure.com/download/publishprofile.aspx.  You’ll authenticate with your Microsoft Account.
  2. You’ll be prompted to download and save a .publishsettings file.  The .publishsettings file contains a list of all subscriptions for which your Microsoft Account is an admin or co-admin, as well as a base64 encoded management certificate.
  3. Windows Azure will automatically associate the newly created management certificate with every subscription for which your Microsoft Account is an admin or co-admin.

With the .publishsettings file you can execute the Import-AzurePublishSettingsFile command to configure connectivity between your machine, the Windows Azure PowerShell cmdlets, and Windows Azure.  This same file can also be imported into Visual Studio to configure connectivity between Visual Studio and Windows Azure.

Import-AzurePublishSettingsFile <subscription1-subscription2>.publishsettings

WindowsAzurePublishImportWizard

I’ve noticed some people repeatedly following step 1 in the many tutorials and quick starts – repeatedly executing Get-AzurePublishSettingsFile.  There is really no need to follow those same steps each time.  In fact, it’s probably a bad thing (to do each time).  Instead, manually configure the connectivity between your machine and Windows Azure.  If you already have a management certificate on your machine and in the Windows Azure subscription you want to manage, you can use that certificate (instead of one created by Get-AzurePublishSettingsFile).  You just need to write a few more lines of PowerShell, such as the following:

$subscriptionName = ‘<SUBSCRIPTION_NAME>’
$subscriptionId = ‘<SUBSCRIPTION_ID>’
$thumbprint = ‘<MANAGEMENT_CERTIFICATE_THUMBPRINT>’
$mgmtCert = Get-Item cert:\\CurrentUser\My\$thumbprint

# Configure the subscription details in the Windows Azure PowerShell cmdlets
Set-AzureSubscription -SubscriptionName $subscriptionName -SubscriptionId $subscriptionId -Certificate $mgmtCert

# Make the default
Set-AzureSubscription -DefaultSubscription $subscriptionName

# Configure the subscription to use the storage account
Set-AzureSubscription -SubscriptionName $subscriptionName CurrentStorageAccount ‘mystorageaccount’

 

Personally this is the approach I use nearly all the time.  It’s a little more work, but I gain more control over the subscriptions that I’m managing using either PowerShell or Visual Studio.  I hope this helps to clear up some confusion on how to configure your machine to work with Windows Azure.

About these ads
Tagged with: ,
Posted in Windows Azure
5 comments on “Configuring Connectivity with Windows Azure PowerShell Cmdlets
  1. [...] Blog: Configuring Connectivity with Windows Azure PowerShell Cmdlets – by @michaelcollier (posted Feb. 28) [...]

  2. [...] Blog: Configuring Connectivity with Windows Azure PowerShell Cmdlets – by @michaelcollier (posted Feb. 28) [...]

  3. [...] Blog: Configuring Connectivity with Windows Azure PowerShell Cmdlets – by @michaelcollier (posted Feb. 28) [...]

  4. Yossi Dahan says:

    Very good post Michael thanks. also worth mentioning that the Import-AzurePublishSettingsFile caches the credentials in the user account so there’s certainly no need to do this again on the same machine for the same user anyway, I’ve written about this here – http://yossidahan.wordpress.com/2012/12/12/azure-subscriptions-in-powershell-demystified/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow Michael S. Collier's Blog on WordPress.com
Follow

Get every new post delivered to your Inbox.

Join 1,752 other followers

%d bloggers like this: