New Role within Microsoft

I have a new job! 🙂

As of 1/28/2013 I will move over to the Windows Azure Runtime team as a Senior Program Manager. So instead of just talking about how great Windows Azure is I’ll have the opportunity to make it even better.

My initial focus will be on the Developer and IT Pro client experience. This will mean a lot of work focusing on Cloud Services(PaaS) and Virtual Machines(IaaS) usability and functionality. The first order of business is building improving upon the command line and SDK experience for our compute options.

I’m very open and interested in feedback so please let me know how I can help 🙂

Michael Washam
mwasham at

Importing and Exporting Virtual Machine Settings

I wanted to highlight the Export-AzureVM and Import-AzureVM cmdlets as I’ve seen quite a few recent cases where they come in handy when dealing with Windows Azure Virtual Machines.

Here are a few places where they can be exceptionally useful 🙂

Situation #1: Deleting a Virtual Machine when you are not using it and restoring it when you need it
Windows Azure billing charges for virtual machines whether they are booted or not. For situations where you have an “on and off” type of deployment such as development and test or even applications that don’t get as much usage after hours having the ability to save all of the current settings and remove and re-add later is huge.

Situation #2: Moving Virtual Machines between Deployments
If you ever find yourself in the situation where you need to remove and re-configure a VM in a different deployment. This could happen because you booted the VM up but placed it in the wrong cloud service or you misconfigured the virtual network and have to reconfigure.

There are likely many more scenarios but these seem to be the most common.

So here are a few examples to show how it works:

Exporting and Removing a Virtual Machine

# Exporting the settings to an XML file 
Export-AzureVM -ServiceName '<cloud service>'  -Name '<vm name>' -Path 'c:\vms\myvm.xml'
# Remove the Virtual Machine 
Remove-AzureVM -ServiceName '<cloud service>'  -Name '<vm name>'  

Note: Remove-AzureVM does not remove the VHDs for the virtual machines so you are not losing data when you remove the VM.

If you open up the xml file produced you will see that it is a serialized version of your VM settings including endpoints, subnets, data disks and cache settings.

At this point you could easily recreate the same virtual machine in a new or existing cloud service (specify -Location or -AffinityGroup to create a new cloud service). This operation could easily be split up into a few scheduled tasks to automate turning on and turning off your VMs in the cloud to save money when you aren’t using them.

Import-AzureVM -Path 'c:\vms\myvm.xml' | New-AzureVM -ServiceName '<cloud service>' -Location 'East US' 

For more than a single VM deployment PowerShell’s foreach comes to the rescue for some nice automation.

Exporting and Removing all of the VMs in a Cloud Service

Get-AzureVM -ServiceName '<cloud service>' | foreach { 
    $path = 'c:\vms\' + $_.Name + '.xml'
    Export-AzureVM -ServiceName '<cloud service>' -Name $_.Name -Path $path
# Faster way of removing all VMs while keeping the cloud service/DNS name 
Remove-AzureDeployment -ServiceName '<cloud service>' -Slot Production -Force 

Re-Importing all of the VMs to an existing Cloud Service

$vms = @()
Get-ChildItem 'c:\vms\' | foreach {
	$path = 'c:\vms\' + $_
	$vms += Import-AzureVM -Path $path
New-AzureVM -ServiceName '<cloud service>' -VMs $vms

Handy Library for Dealing with Transient Connectivity in the Cloud

The Windows Azure CAT team has built a library (available via Nuget) that provides alot of functionality around handling transient connection problems across the Windows Azure Platform with SQL Azure, ServiceBus, Cache, Configuration and Storage supported (this has been around awhile but it’s the first chance I’ve had to try it out).

To use add the TransientFaultHandlingFx reference:


In addition to adding the assemblies it also adds a .chm to your project with full documentation on how to use the library.

There are numerous ways to actually use the library. For SQL Azure I would recommend reading the whitepaper the Windows Azure CAT team published.

The method I chose was to configure a retry policy in my web/app.config:

 <section name=”RetryPolicyConfiguration” type=”Microsoft.AzureCAT.Samples.TransientFaultHandling.Configuration.RetryPolicyConfigurationSettings, Microsoft.AzureCAT.Samples.TransientFaultHandling” />
<RetryPolicyConfiguration defaultPolicy=”FixedIntervalDefault” defaultSqlConnectionPolicy=”FixedIntervalDefault” defaultSqlCommandPolicy=”FixedIntervalDefault” defaultStoragePolicy=”IncrementalIntervalDefault” defaultCommunicationPolicy=”IncrementalIntervalDefault”>
 <add name=”FixedIntervalDefault” maxRetryCount=”10″ retryInterval=”100″ />
 <add name=”IncrementalIntervalDefault” maxRetryCount=”10″ retryInterval=”100″ retryIncrement=”50″ />
 <add name=”ExponentialIntervalDefault” maxRetryCount=”10″ minBackoff=”100″ maxBackoff=”1000″ deltaBackoff=”100″ />

From there it’s simple to create a RetryPolicy object from the configuration:

public static RetryPolicy GetRetryPolicy()
 // Retrieve the retry policy settings from the application configuration file.
 RetryPolicyConfigurationSettings retryPolicySettings = ApplicationConfiguration.Current.GetConfigurationSection<RetryPolicyConfigurationSettings>(RetryPolicyConfigurationSettings.SectionName);
// Retrieve the required retry policy definition by its friendly name.
 RetryPolicyInfo retryPolicyInfo = retryPolicySettings.Policies.Get(“FixedIntervalDefault”);
// Create an instance of the respective retry policy using the transient error detection strategy for SQL Azure.
 RetryPolicy sqlAzureRetryPolicy = retryPolicyInfo.CreatePolicy<SqlAzureTransientErrorDetectionStrategy>();
return sqlAzureRetryPolicy;

You can pass the RetryPolicy object to the extension methods (for ADO.NET in my example):

sqlCon.OpenWithRetry(rp); // for SqlConnection
object rValue = sqlCmd.ExecuteScalarWithRetry(rp); // from SQLCommand

There is functionality for LINQ as well.

This library not only makes your code robust but can save you a massive amount of time too since they have already put the resources into testing/debugging it 🙂