Creating Azure VMs with Powershell
Steve Jennings
by Steve Jennings

First post! How exciting! I should’ve started this long ago…

Since I wrote this, I’ve moved beyond using Powershell for deploying new virtual machines. But I’m slowly getting back to this script. A lot has changed since it was first written. Since the script was originally made - Azure has deployed quite a bit with such updates as…

This post, I hope, helps the operations guy (colloquially named a ‘Sysadmin’ or ‘System Administrator’ in some circles) manage deployments to the Public Cloud using Windows Powershell.

About a year and a half ago, we were being tasked with a redesign of our primary web system. This was a big challenge. I believe it was considered such at the time because hybrid cloud environments were just really ramping up. The organization had no experience in the public cloud and had no semblence of how to approach a redesign for the website. Since I handled most of the infrastructure for the old site, I figured, why not give Azure a shot (we chose Azure at the time, mostly because AWS had no support for Server Message Block 3.0, for those wondering. Amazon has since fixed this oversight). I had not touched any of these services before and thought of it as a learning opportunity.

As a result, there was practically not much in the way of tooling and Azure had just deployed their new platform, Resource Manager. Documentation was being migrated to their new documentation system and ultimately not many people I spoke to had any idea on how to approach building machines in a quick, efficient manner. So this script was actually an early foray into getting systems deployed on Azure using the tool I was familiar with at the time which was Powershell.

I first attempted to treat Azure like I could any other private cloud provider and that was a huge mistake. I learned some valuable lessons in attempting to keep up to speed on deploying new systems in Azure. It was what formulated the reasoning to create the script.

Here’s some of those pain points by treating it like our private cloud:

  • I treated our virtual machines as special snowflakes.
  • I manually built these machines, and manually configured them.
  • I had challenges trying to utilize the cloud platform design because the previous decisions hampered growth.
  • I had an issue dealing with the decoupled nature of building Azure Compute resources

…all of which contributed to a domino effect of failing to accurately update.

Ultimately I came to the conclusion that I needed to utilize Powershell to handle most of the heavy lifting for new deploying new virtual machines.

My Powershell script would do the following:

  • Grab input and verify input
  • Dynamically check to ensure that naming conventions with specific resources are properly adhered to
  • Attempt to provide error checking
  • Utilize Azure Managed Disks and check whether a size is capable of using one or the other
  • Utilize the ability to check against VM size and utilize enhanced networking

Here’s the script:

Create-AzureManagedVM.ps1

There’s in fact quite a few things I’d like to improve… now that the new Az module is on the way:

  • Add support for managed images
  • Possibly query the Azure API for various tasks
  • Clean up the parametersets in the script to separate VHDs from images
  • Convert logic and commands entirely to utilize the new Az module