PowerShell: Updating an Azure Service Display Name

If you’re like me, you probably like clarity, consistency, and conciseness. Given that, I like to ensure that names of hosted services in Windows Azure are named appropriately. Sometimes developers will give a service a quick name that they understand, but may not relay enough information to other team members, at a glance, as to what that service does.

Thankfully, this is easily rectified using a simple PowerShell command. Assuming that you have already configured your Windows Azure PowerShell cmdlets according to my recent “Introduction to Azure PowerShell Module” article, you can simply run the following command to update the Label (aka. “friendly name”) of a Windows Azure hosted service.

1
2
3
4
# Select the Windows Azure subscription that we are working with (must be configured using Set-AzureSubscription)
Select-AzureSubscription -SubscriptionName Development;
# Set the new friendly name (label) for the service
Set-AzureService -ServiceName MyService -Label "This is my new service label";

If you want to take it one step further, you can build a .NET [HashTable] of key-value mappings that link service names to their respective labels. Then, once you’ve got the mapping, you can simply iterate over it and call Set-AzureService for each entry. This method is a lot more flexible and efficient with writing code :)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Select the Windows Azure subscription
Select-AzureSubscription -SubscriptionName development;

# Build a HashTable of service names and labels
$ServiceList = @{
    'Service1' = 'My First Service';
    'Service2' = 'My Second Service';
    'Service3' = 'My Third Service';
};

# For each service entry in the HashTable, update the Label field
foreach ($Service in $ServiceList.Keys) {
        Set-AzureService -ServiceName $Service -Label $ServiceList[$Service];
};

Pretty easy, isn’t it?

“Why go through all that effort? I’ll just do it through the UI.”

Did I happen to mention that the Windows Azure Silverlight user interface (UI) doesn’t even allow you to change the label / friendly name of a hosted service once it has been created? Yes, it’s true (as far as I know). The only option to re-label an Azure hosted service through the management UI, once it has already been defined, is to delete the existing service definition, and recreate it. That doesn’t sound like a viable option in a production environment now, does it? :)

Until next time … enjoy scripting ALL the things in PowerShell!

Introducing Microsoft’s OFFICIAL Windows Azure PowerShell Module!

Hello folks! Today, Microsoft has officially announced the availability of a new PowerShell module to help manage Windows Azure features! In order to obtain this module, you will need to download the Web Platform Installer 4.0 (x64, x86). Once you’ve installed the Web Platform Installer 4.0, you’ll need to search for “PowerShell” and install the “Windows Azure PowerShell” package from it.
Continue reading

PowerShell: Automate Windows Azure Service Bus queue creation

One of the core services provided by the Windows Azure “cloud computing” platform is the ability to create first-in, first-out messaging queues. These queues are considered to be part of the Service Bus feature in Windows Azure. In some cases, it may be desirable to automate the creation of these queues, especially if there are a lot of them to create. By automating this process, rather than performing it manually, you can ensure consistency, repeatability, and speed.

Starting out with Windows Azure automation might lead you to download the official Microsoft Windows Azure cmdlets, or even the third-party Cerebrata Windows Azure module for Windows PowerShell. The latter module appears to have cmdlets that support queue creation, however the former (Microsoft) module does not. If you’d rather not spend the money on the Cerebrata module, can’t get your company to buy it for you, or you’d rather just stick to native Microsoft stuff, you’re still in luck. The Windows Azure .NET SDK 1.6 allows C# developers, and PowerShell script writers, to create queues using the provided .NET types!
Continue reading

PowerShell: Get the Windows Azure Certificate

If you’re automating Windows Azure using Windows PowerShell, one of the first things you’ll probably notice is that you need a management certificate to connect to the Windows Azure subscription that you’re attempting to view or modify. Management certificates are associated to a Windows Azure subscription inside the Management Portal, under the Hosted Services, Storage Accounts & CDN –> Management Certificates section (see screenshot).

Windows Azure - Management CertificatesOnce you have associated a management certificate with a subscription, it needs to be imported into your local computer’s certificate store so that it can be used from PowerShell to manage the Azure subscription. To do this, follow these directions:

  1. Open MMC
  2. Add the certificates snap-in (for current user or local computer)
  3. Navigate to the Personal –> Certificates “folder”
  4. Right-click the Certificates node and select All Tasks –> Import
  5. Select the file on the filesystem that contains the certificate
  6. Select the Personal certificate store if necessary and finish the import wizard
Next, you’ll need to grab the certificate’s thumbprint, which is basically a unique identifier that differentiates it from other certificates. To grab this, follow these steps:
  1. Double-click the certificate in the Certificates MMC snap-in
  2. Visit the Details tab
  3. Scroll down to the Thumbprint field and copy the value into Metapad or equivalent

Now that you’ve taken down the thumbprint of the certificate, you can use PowerShell to retrieve the certificate from the current user’s certificate store. If the certificate resides in the local computer’s certificate store, you’ll have to replace “CurrentUser” with “LocalMachine.” To get the certificate, check out the code below.

1
2
$AzureCertThumbprint = '4DAE6C3F444F21972B0823467C229605';
$AzureCert = Get-Item -Path cert:\CurrentUser\My\$AzureCertThumbprint;

The $AzureCert variable now holds a reference to the management certificate, and you can now use this to manage your Windows Azure subscription!