By Richard Conway

Many people start their Windows Azure journey with a simple web role deployed through the integrated Visual Studio tools. They soon learn that Windows Azure is a rich ecosystem of interconnecting parts and services which can be used to smoothly replace or augment an on-premise system.

Service Management is one key part of that infrastructure. I want to paraphrase some material that I normally speak or write about in a short piece on how to manage services and what to use.

Two products we’ll focus on are Cerebrata CmdLets and our own Azure Fluent Management library. The first is a paid product which will make your life considerably easier and is a must for using in any Continuous Integration process. It gives you a phenomenal abstraction to your deployment and thus simplifies it considerably allowing you to spend more time coding. Cerebrata CmdLets are available through their website ( They have become one of the Azure industry staples. They are a Powershell set of scripts so eminently malleable.

I’m now going to decompose a script using Cerebrata CmdLets to deploy an application to Windows Azure. It’s worth noting that the 3 steps that are apparent here are actually 5 steps as a task-based Service Management exercise. These are:

  • Create a storage account
  • Create a Blob Container
  • Upload a package to the blob container
  • Create a hosted service
  • Deploy to that hosted service

Powershell CmdLets should be setup in advance and then a simple command can be issued to get all of the available CmdLet names and descriptions.

Get-Command –PSSnapin AzureManagementCmdletsSnapIn

Variables can be defined which will allow me to construct my hosted service. These include Subscription Id, a name for the Service (which will be {name} and a location.

$subscriptionid = '67xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
$hostedservicename = 'ukwaughosted'
$location = 'North Europe'
$hostedservicedesc = 'The UK Windows Azure Users Group'

After I’ve added all of my meta-information I can go ahead and get a Certificate (from a local certificate store) which has been pre-uploaded to the Management Certificates section of the Azure portal and then call the New-HostedService CmdLet

$certificate = Get-ChildItem -path cert:\CurrentUser\My\AA4EF678D0961B6A6C51D4AC657B0ADB71BB3354

New-HostedService -ServiceName $hostedservicename -Label $hostedservicename -SubscriptionId $subscriptionid -Location $location -Description $hostedservicedesc -Certificate $Certificate

After completing this we will want to deploy a package. To achieve this we’ll have to upload this package to Blob storage as a separate step which means creating the account and container, then uploading the package (a .cspkg file) and then consuming it for a deployment.


$CscfgFile = 'C:\Projects\Tech Projects\London Windows Azure User Group\HelloCloud\HelloCloud\bin\Release\app.publish\ServiceConfiguration.Cloud.cscfg'

$CspkgFile = 'C:\Projects\Tech Projects\London Windows Azure User Group\HelloCloud\HelloCloud\bin\Release\app.publish\HelloCloud.cspkg'

New-Deployment -Slot Production -PackageLocation $CspkgFile -ConfigFileLocation $CscfgFile -Label 'UKWAUG Deployment' -ServiceName $hostedservicename -RunDeploymentAfterCreation $TRUE -TreatWarningsAsError $FALSE -SubscriptionId $subscriptionid -Certificate $certificate


There you go. Nothing more to it than that! The compositions of the scripts you can produce are fairly rich and can cover all manner of scenarios you would need in any deployment.

Cerebrata Powershell CmdLets are great for enterprise application deployments with Windows Azure where you can use the power of Powershell (no pun intended!) to drive package deployment and cover all of the scenarios. While they can be used in a C# application like any Powershell script it’s not really a natural state for them.

I’d like to describe our library Azure Fluent Management, which can be downloaded from nuget. It wouldn’t be used in a CI or build process. It can be used for “Reactive Management”, which would entail a cascade of deployments, updates or deletions of services within Azure as a rules-based approach within an application, be it an ASP.NET or a Windows application.

We’ll take a look at the deployments shortly but first we’ll see the power of coupling creating things such as a SQL Azure database and an Azure Storage account in a single transaction. Having this context awareness in the library makes a good all or nothing strategy. It doesn’t have to be used but are a powerful feature.

var subscriptionManager = new SubscriptionManager(ExampleConstants.SubscriptionId);
var sqlAzureManager = subscriptionManager.GetSqlAzureManager();
var storageManager1 = subscriptionManager.GetStorageManager();

The above allows us to get a handle to our subscription and sets up the consumption of messages through the event handlers.

Below we’ll use a single line of code to describe the creation of a SQL Azure instance, the addition of an Admin user, the creation of 3 separate firewall rules, the creation of a database admin and the execution of scripts against the newly created database.


   var trans1 = sqlAzureManager.AddNewServer(ConstantsLocationWestEurope)
.AddNewFirewallRule("myofficeip", "", "")
.AddNewFirewallRule("anotherip", "", "")
.WithSqlAzureCredentials("ukwaug", M@cc0mputer)
.AddNewDatabaseAdminUser("ukwaugdb", M@cc0mputer)
.ExecuteScripts(@"C:\Projects\Tech Projects\Elastacloud")
Similarly we may want to do the same with a storage account as below.
 var storage1 = storageManager1.CreateNew("elastadfg1")
.WithDescription("my new storage")

To couple the two of these together is fairly trivial. Now if one part fails then all activities fail.

var orchestrator = new ServiceOrchestrator
var success = orchestrator.Commit();

For completeness we’ll look at how to deploy something using Fluent Management. There are myriad options but I’ve taken a fairly complex scenario here to show the superset rather than a simple deployment. The following will take a package file and deploy to Windows Azure whilst creating a self-signed Service Certificate and a Remote Desktop account. Certain actions require on the fly rebuilds because of the design of the package. At the time of release of this article I know this to be changing so in future versions we’ll cut the dependency on msbuild and cspack.


var subscriptionManager = new SubscriptionManager(ExampleConstants.SubscriptionId);
      var deploymentManager = subscriptionManager.GetDeploymentManager();
       .WithUsernameAndPassword("xyz", "xyzM123")
.AddDescription("My new hosted services")

In this short piece I’ve introduced two powerful and yet very different ways of deploying applications and setting up services for Windows Azure. Both, especially the former, offer rich ways of interacting with the Fabric and Management APIs. For more information on either see where you’ll see the rich toolset that Cerebrata provide for reasonable prices in addition to Powershell CmdLets. Check out our Blog as well for more information on Azure Fluent Management at


16ea31d[1]Richard Conway
Elastacloud Limited

Richard is a Director of Elastacloud Limited, co-founder of the UK Windows Azure Group and author of the Azure Fluent Management library which is available for download from nuget. Richard has 16 years’ commercial experience with mainly Microsoft technologies. During this time he has written 8 books and numerous articles and worked for a myriad of clients in the City of London. He has been wholly devoted to Windows Azure evangelism and development since its release in 2008. He can be reached @azurecoder or