Book a Demo Free Trial

Scale Your Windows Azure Instances With Azure Management Cmdlets

Gaurav Mantri

May 17, 2011

Category: Azure Subscription

Today (17th May 2011), we released a new version of Azure Management Cmdlets (2011.05.14.00). This release included 3 new cmdlets for managing deployments of your hosted services. To read more about this release please visit: http://www.cerebrata.com/products/azure-management-cmdlets/introduction. One of the cmdlet we introduced in this release is ”Set-RoleInstanceCount”. Till now to scale up or down, you would need to change the instance count by manually editing the configuration file (*.cscfg) and save that configuration file. Now you can use this cmdlet to scale up/down your role instances with very minimal code and without having to manually changing the configuration file. In this blog post I will show you how to use this cmdlet for scaling your role instances. Below is the sample PowerShell script that you can use for execution of this cmdlet.
# Subscription Id
$subscriptionId = “<your subscription id>”;
# API Certificate (This certificate must already be associated with your subscription)
# Following example illustrates how to create a certificate object from a certificate file
$certificate = New-Object System.Security.Cryptography.X509Certificates.X509Certificate;
$certificate.Import(“<path to the certificate file (*.cer)>”);
# Name of the hosted service
$serviceName = “<name of the hosted service>”;
# Slot (Production or Staging)
$slot = “<name of the slot: Production or Staging>”;
# Role name
$roleName = “<name of the role>”;
# New instance count
$instanceCount = “<new instance count>”;
Set-RoleInstanceCount -ServiceName $serviceName -Slot $slot -RoleName $roleName -InstanceCount $instanceCount -SubscriptionId $subscriptionId -Certificate $certificate -WaitToComplete
Here is a brief explanation of the parameters:
$subscriptionId
This is your Windows Azure subscription id which you can get from Windows Azure Portal.
$certificate
This is the API certificate. This must be uploaded already in Windows Azure Portal.
$serviceName
Name of your hosted service.
$slot
Slot (Production or Staging) in which your hosted service is currently deployed.
$roleName
Name of the role which you wish to scale up or down.
$instanceCount
This is the new instance count.
Once this cmdlet is executed, what it does is that it fetches the configuration file for you, updates the “Instance” node with new count value and then updates the configuration file.
Now with this cmdlet, you can be very creative and scale up or down your instances based on any set of parameters. For example, you can scale down your instance counts to 1 over the weekends and then scale it back up on Monday morning.
Do try it out and let us know how it has worked for you. You can download the latest version from here: http://www.cerebrata.com/products/azure-management-cmdlets/introduction.