Monday, July 22, 2013

Building a Hyper-V Windows Server in under 3 seconds

I find myself building VMs almost on a daily basis. If I am not building a proof of concept or a demo for a client, I am testing different configurations or architectural approaches to solutions, testing new features of SQL Server, Cumulative Updates etc... Whatever the reason might be, creating a new VM always takes valuable time.

Back in April I blogged about using Hyper-V as your virtualization platform for a lab environment. I walked through building a template Virtual Server and then creating a base drive to be used to build new machines from. Using a combination of base and differential drives reduces the time that it takes to provision a new VM dramatically as you don't have to install the operative system every time. However, it still takes a few minutes to walk through the Hyper-V manager wizards to create your differential disk and new machine. Let's see how to take things to the next level by using two simple PowerShell commands to build your differential disk and Virtual Server.

Assumptions: For these commands to work you must already have a base drive to be used as the parent drive for the differential disk. For step by step instructions creating a base drive check my previous blog post Setting Up a Virtual Server Lab With Hyper-V.

Let's get started...

The goal here is to avoid going through the Hyper-V manager and use PowerShell commands to provision your new VM. See the script below.

Let's take a look at the few lines that initialize the variables that we are going to use as parameters.

#Set variables
$Name = "VMName" #This is the Hyper-V name of the Virtual Machine
$ParentPath = "D:\Hyper-V\Virtual Hard Disks\WS2012Base.vhdx" #Path to the base drive
$DiskPath = "H:\Hyper-V\"+$Name+"\"+$Name+".vhdx" #Path for the differential drive, I use my SSD for this
$VMPath = "D:\Hyper-V\"+$Name+"\" #Path for the Virtual Machine definition files

Then we execute the command to create the differential disk using the variables initialized above.

#Create new differential disk
New-VHD -ParentPath $ParentPath -Path $DiskPath -Differencing -SizeBytes 60GB  

And lastly, we run the command to create the VM using the differential disk created in the previous step.

#Create VM
New-VM -VHDPath $DiskPath -ComputerName "localhost" -MemoryStartupBytes 4GB -Name $Name -Path $VMPath -SwitchName "External Network"

Here it is without the comments:

$Name = "VMName" 
$ParentPath = "D:\Hyper-V\Virtual Hard Disks\WS2012Base.vhdx" 
$DiskPath = "H:\Hyper-V\"+$Name+"\"+$Name+".vhdx" 
$VMPath = "D:\Hyper-V\"+$Name+"\"

New-VHD -ParentPath $ParentPath -Path $DiskPath -Differencing -SizeBytes 60GB  

New-VM -VHDPath $DiskPath -ComputerName "localhost" -MemoryStartupBytes 4GB -Name $Name -Path $VMPath -SwitchName "External Network"


I typically start the VMs with 4GB of RAM and 60GB of maximum disk space so I hard coded those values in the command. Of course you can substitute those values with additional variables and initialize them in the first step.

In my system, running these two PS commands take 2 to 3 seconds and I am ready to go. That is it! Talk about time savings.

Check out the New-VHD and  New-VM TechNet documentation pages for more information and additional options regarding these two Hyper-V commands.

Sunday, July 7, 2013

SQL Saturday #226 - South Florida

For the second time, I had the pleasure and honor to be part of the organizer's board for SQL Saturday - South Florida 2013. To be part of such a great community event was without a doubt one of the best professional experiences I've had. I worked closely with so many great people including speakers, sponsors, volunteers, fellow organizers and of course the attendees. The networking opportunities were incredible.  It was great to hear so many success stories from people having one thing in common. They all attended SQL Saturday at one point during the last few years and have since then found a path to professional excellence and their ideal jobs. 

This year we set a new record for the number of registrations. We were 2 registrations shy of 800. That is right! 798 registrations. I put together a quick video using Geoflow that shows the registrations by zip code over time.


SQL Saturday #226 - South Florida from Luis Figueroa on Vimeo.

I also had the pleasure of hosting one of the sessions. In this presentation I provided an overview of SQL Server Master Data Services 2012 titled Getting started with MDS 2012.

I have posted the slides in slideshare and embedded a link below.

Lastly, if you are a data professional or you just have an interest in the field, I would like to invite you to become part of the PASS community. Getting involved is easy, visit to get started.     If you are in South Florida, you can attend any of the local chapter meetings:

I look forward to seeing everyone once again at SQL Saturday - South Florida 2014!

If you are interested in attending one of my presentations please visit my whereabouts page for information on upcoming speaking engagements.

Luis Figueroa

Thursday, April 4, 2013

Setting Up a Virtual Server Lab With Hyper-V

For years I had used VMware as my hypervisor of choice for virtual labs but I recently switched to Hyper-V. The last few weeks I have been getting familiar with how things work in Microsoft's virtualization environment and decided to write a quick step by step on how to get a virtual lab up and running. Before I get started with that I would like to share some of the reasons why I decided to switch.

  • Hyper-V is now included with Windows 8 Pro and Enterprise editions (No need to spend extra money for cutting edge virtualization technology on my laptop or workstation)
  • Hyper-V has matured now to a point where it can now make a great case for enterprises to adopt this technology over any other virtualization platform so I would expect to see more enterprises running their private clouds on Hyper-V. See Hyper-V competitive advantage datasheet
  • I am a Microsoft Certified Professional / Trainer and I work for a Microsoft Gold Partner. There is a great deal of support offered to IT professionals focused on Microsoft technologies and many of the demos / labs are available in the form of Hyper-V virtual machines. It would not be worth it to take the extra time to recreate such resources from scratch using a different virtualization technology.
  • I see I great deal of opportunities derived from the Azure IaaS offering and it's ability to run Hyper-V machines. I can create a Virtual Server and run it on my laptop, the Data Center or upload it to the cloud. 
  • I can browse a VHD as if it were just another disk. 
  • I can boot my windows computer from a VHD

Now, back to the original subject. Let's get started.

Enabling Hyper-V

First things first, right? if you have not already enabled Hyper-V in your windows 8 Pro or Enterprise OS you can do so by executing the following PowerShell command:

enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All