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.
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
This will be listed at the bottom if Azure is available.
Import the module using Import-Module Azure
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.
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.
Get-AzureSubscription -Default returns the default subscription.
Get-AzureSubscription -Current returns the currently selected subscription.
If you have multiple subscriptions with the same name then the -ExtendedDetails parameter is useful to determine what is what.
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.
Use the Remove-AzureAccount and then use the Get-AzurePublishSettingsFile to get the certificate for the subscription to enable non-interactive authentication.
[Updated 16/03/2016]
Using PublishSettingsFile
First of all run Get-AzurePublishSettingsFile
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.
Next import the publish settings file using Import-AzurePublishSettingsFile -PublishSettingsFile FileName…
When you run Get-AzureSubscription you’ll notice your subscription will contain a certificate, you should now delete the downloaded .publishSettings file.
Run some commands against your subscription…Get-AzureVM…Get-AzureStorageAccount…
One comment