Connecting to Windows Azure with PowerShell

Installing the PowerShell module

First of all you need the Windows Azure PowerShell module which can be downloaded from here.

InstallPoSHModule

The module is installed via the Microsoft Web PI, simply follow the installer. If PowerShell is open when you install the Windows Azure module simply restart PowerShell i.e. close it and reopen.

Next check the module is available using Get-Module -ListAvailable

GetModule

This will be listed at the bottom if Azure is available.

AzureModule

Import the module using Import-Module Azure

ImportModule

Get-Command -Module Azure will give you a list of the available commands.

Connecting to Azure

[Updated 16/03/2016]:

If you’re looking to use an interactive PowerShell session with Azure then the Add-AzureAccount cmdlet is suitable; this will give you a 12 hour session token; after this time you need to re-authenticate.

AddAzureAccount

Enter your email address associated with the Azure subscription and follow the prompts. Once you have authenticated return to PowerShell and type Get-AzureSubscription to see your subscriptions.

If you have multiple subscription then you’ll need to determine which one if default and which is current.

AzureSubscriptions

Get-AzureSubscription -Default returns the default subscription.

defaultSub

Get-AzureSubscription -Current returns the currently selected subscription.

currentSub

If you have multiple subscriptions with the same name then the -ExtendedDetails parameter is useful to determine what is what.

extendedSub

Now comes the question…how do I authenticate against Azure when scripting? Well you need to use the PublishSettingsFile but If you’ve already added the subscription using the Add-AzureAccount cmdlet you’ll need to remove it first.

scriptingSub1

Use the Remove-AzureAccount and then use the Get-AzurePublishSettingsFile to get the certificate for the subscription to enable non-interactive authentication.

removeSub

[Updated 16/03/2016]

Using PublishSettingsFile

First of all run Get-AzurePublishSettingsFile

GetPublishSettingsFile

This will open an internet browser and you’ll be prompted to enter your credentials associated with your Azure subscription, once authenticated a publishsettings file will be downloaded.

PublishSettingsFile

Next import the publish settings file using Import-AzurePublishSettingsFile -PublishSettingsFile FileName…

PublishSettingsFile1

When you run Get-AzureSubscription you’ll notice your subscription will contain a certificate, you should now delete the downloaded .publishSettings file.

Subscription1

Run some commands against your subscription…Get-AzureVM…Get-AzureStorageAccount…

 

Advertisements

One comment

  1. Pingback: Spinning up and spinning down Azure VMs | Notes from stuff I'm working on

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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s