We have a new release of the Windows Azure PowerShell cmdlets that we hope will make getting started and scripting with the cmdlets a much easier task.
The new release can be downloaded from its CodePlex project site here.
Getting Started Improvements
In 2.2.2 we have added a start menu link that starts a PowerShell session with the Windows Azure cmdlets already loaded. We have also added a Start Here link that shows how to complete the setup and a short tour about the capabilities of the Windows Azure PowerShell cmdlets and release changes.
Subscription Management Improvements
We have taken the subscription management improvements from the 2.2 release and made them much better.
Specifically, we have added the ability to persist your subscription settings into your user profile. This functionality allows you to set the subscription data once and then in new scripts or PowerShell sessions just select the subscription you want to use without the need to specify the subscription ID, Certificate and storage accounts each time.
Code Snippet One: Setting Subscription Data
$subid = “{subscription id}”
$cert = Get-Item cert:CurrentUserMyCERTTHUMBPRINTUPPERCASE
# Persisting Subscription Settings
Set-Subscription -SubscriptionName org-sub1 -Certificate $cert -SubscriptionId $subid
# Setting the current subscription to use
Select-Subscription -SubscriptionName org-sub1
Calling the Set-Subscription cmdlet with your certificate and subscription ID. Set-Subscription will persist the certificate thumbprint and subscription id to (C:Users{username}AppDataRoamingWindows Azure PowerShell CmdletsDefaultSubscriptionData.xml) associated with the subscription name.
This functionality supports adding multiple subscriptions to your configuration so you can manage each individually within the same script simply by calling Select-Subscription with the subscription name.
Code Snippet Two: Setting the Default Subscription
Set-Subscription -DefaultSubscription org-sub1
Snippet two demonstrates setting the default subscription to use if you do not set one with Select-Subscription.
Code Snippet Three: Associating Storage Accounts with your Subscription
# Save the cert and subscription id for two subscriptions
Set-Subscription -SubscriptionName org-sub1 -StorageAccountName stname1 -StorageAccountKey mystoragekey1
Set-Subscription -SubscriptionName org-sub1 -StorageAccountName stname2 -StorageAccountKey mystoragekey2
# Specify the default storage account to use for the subscription
Set-Subscription -SubscriptionName org-sub1 -DefaultStorageAccount stname1
Snippet three shows that you can associate multiple storage accounts with a single subscription. All it takes to use the correct storage account is to set the default before calling a cmdlet that requires a storage account.
Code Snippet Four: Specifying the Subscription Data File Location
# overriding the default location to save subscription settings
Set-Subscription -SubscriptionName org-sub1 -Certificate $cert -SubscriptionId $subid -SubscriptionDataFile c:mysubs.xml
# retrieving a list of subscriptions from an alternate location
Get-Subscription -SubscriptionDataFile c:mysubs.xml
Each of the subscription cmdlets take a -SubscriptionDataFile parameter that allows you to specify which XML file to use for operations.
Code Snippet Five: MISC Subscription Management=
# Returns all persisted settings
Get-Subscription
# Removes mysub2 from persisted settings
Remove-Subscription -SubscriptionName org-sub2
# Removing a storage account from your persisted subscription settings
Set-Subscription -SubscriptionName org-sub1 -RemoveStorageAccount stname1
Other Usability Improvements
We have made many of the cmdlets simpler to use by allowing more parameters to be optional with default values.
- Label parameter is now optional in New-AffinityGroup, Set-AffinityGroup, New-HostedService, New-StorageAccount, New-Deployment and Update-Deployment.
- Slot parameter is now optional in New-Deployment and Update-Deployment (Production slot is used by default).
- Name parameter is now optional in New-Deployment (a Globally Unique Identifier value is used by default).
In addition to the defaults we provided some needed fixes to unblock certain scenarios.
- Get-Deployment now returns $null if no deployment was found in the specified slot (an error was thrown in previous versions).
- Package and -Configuration parameters now accept UNC paths in New-Deployment and Update-Deployment.
Breaking Changes
Usability improvements like these did require some sacrifices. Before you download the latest build please review the list below because we have a few breaking changes.
- DefaultStorageAccountName and -DefaultStorageAccountKey parameters were removed from Set-Subscription. Instead, when adding multiple accounts to a subscription, each one needs to be added with -StorageAccountName and -StorageAccountKey or -ConnectionString. To set a default storage account, use Set-Subscription –DefaultStorageAccount {account name}.
- SubscriptionName is now mandatory in Set-Subscription.
- In previous releases, the subscription data was not persisted between PowerShell sessions. When importing subscription settings from a publishsettings file downloaded from the management portal, the Import-Subscription cmdlet optionally saved the subscription information to a file that could then be restored using Set-Subscription thereafter. This behavior has changed. Now, imported subscription data is always persisted to the subscription data file and is immediately available in subsequent sessions. Set-Subscription can be used to update these subscription settings or to create additional subscription data sets.
- Renamed -CertificateToDeploy parameter to -CertToDeploy in Add-Certificate.
- Renamed -ServiceName parameter to -StorageAccountName in all Storage Service cmdlets (added “ServiceName” as a parameter alias for backward compatibility).
Summary
In the 2.2.2 release we have made a number of fixes such as accepting UNC paths and fixing Get-Deployment to not throw an error on empty slots. We have also substantially improved the getting started experience and how you can manage your Windows Azure subscriptions from PowerShell.
The new release can be downloaded here.