InfoWorld: Automate Live VM Export

infoworldThis is kinda cool, but I got published in InfoWorld, in a roundabout manner. J. Peter Bruzzese writes a column for InfoWorld on enterprise Windows. His latest column is about exporting Hyper-V virtual machines using PowerShell. In Windows Server 2012 R2 (and Windows 8.1) you can export a virtual machine even while it is running. Peter wanted to demonstrate with a weekly and monthly scenario using PowerShell to export virtual machines to a new folder and also delete older versions. The end result would be a set of 4 weekly folders and 2 monthly folders. But he needed help with some of the PowerShell so I pulled together a script which is linked in the InfoWorld article.

The script I wrote is a bit more complicated than what Peter originally envisioned. Now, I doubt his goal could be accomplished with a one-liner. So since I needed to write a script, I took the time to make it robust with items such as error handling and parameter validation. I only wanted to develop the script once so why not be thorough?

As I as finishing up the script to Peter’s requirements, I realized this could also be tackled using a PowerShell workflow. One of the limitations in the original script is that it needs to run on the Hyper-V server. I didn’t include any provision for connecting to a remote server. I also recognized that exporting multiple virtual machines could be done in parallel. Although my original script allows the use of background jobs which is sort of like running in parallel. But I thought a workflow version might at least be educational. Here is the Export-MyVM workflow.

Most of the code is the same as the original script, although I removed the WhatIf parameter. You can’t use SupportsShouldProcess in a workflow and I didn’t have the time to fully write my own. The only code that is really workflow specific is this:

Perhaps the biggest advantage is that with a workflow I get automatic support for background jobs and remoting. Now I can execute the workflow against the Hyper-V server.

And I could still create a PowerShell scheduled job on my computer to run this workflow.

By the way, I’m sure you are aware that there are plenty of Hyper-V backup products from companies like Altaro, Veeam and Unitrends (all of whom help support my blog). Some of them even have free versions of their products. So while you can use PowerShell to export VMs that doesn’t mean you should. Although I can see value for a quick and dirty backup. Ultimately, I suppose it is a good thing to have options.


Mini Hyper-V Benchmarks

I’ve received a lot of interest in my mini Hyper-V project. I’m still running preview bits of Microsoft Hyper-V Server 2012 R2. Once final bits are released I’ll do a clean re-install. But until then I’ve been using it running about 4 virtual machines without a hiccup. I was getting some questions about benchmarks so I thought I’d post what information I could.

Part of the challenge in using a benchmarking tool is that I’m running Server Core so most tools won’t run. I was able to install Dacris Benchmarks on the server and run some benchmarks. I didn’t bother with the video tests and not all features of the tool work on Server Core. But I was able to gather enough information if you are interested.

Overall, it looks like a pretty good system for what I need.


I hope it’s obvious this isn’t a production-level server for a datacenter. But for testing and lab work it is more than adequate. and personally, the portable form factor was the driving force. Dacris Benchmarks confirms my theory.


Here are the results from some of the advanced tests.
Memory Transfer Rate for Large Blocks

Memory Transfer Rate for Small Blocks

CPU Parallel Scaling

CPU Pi Calculation

I also decided to grab system information with MSINFO32.EXE.


While not a benchmark, some of you may be interested in the nitty-gritty. You can also download a zip file with the complete NFO file.

Finally, if you missed any of the earlier articles on my project here they are:

Part 1: Intro and Specs
Part 2: Hardware Build
Part 3: Setup
Part 4: Operating System

I expect just about anywhere I will be presenting or training I’ll have this with me so please feel free to find me if you want a closer look.

Mini Hyper-V: Operating System

When we left my project, the new mini server had booted up using Windows Hyper-V Server 2012 R2. This is a server core installation intended to only run Hyper-V, which is perfect for my needs. The server booted up with a temporary name and a DHCP assigned IP address. The next step is configure the server and join it to my test domain.

I could do this all interactively using the sconfig script, but where’s the challenge in that! So I’m going to configure the server from a Windows 8 client with RSAT installed in my target domain. There are ways to configure Hyper-V in workgroup environment but I want to take advantage of domain. It shouldn’t really make any difference but my test domain, Globomantics.local, is running in a Hyper-V environment on my Windows 8 laptop. My mini Hyper-V server will belong to this domain, as will any virtual machines it ends up hosting.

To get started I know the IP address of the new server and credentials for the local administrator account. With this I can use PowerShell remoting, since it is enabled by default in Windows Server 2012. However, on my client, I need to temporarily add the host to the TrustedHosts list. Otherwise, the client won’t trust the server and I won’t be able to connect. In an elevated I’ll run this command.

Using -Force suppresses confirmation prompts. This setting will allow me to connect to any host using an IP address that starts with 172.16. I should now be able to use Invoke-Command or run any configuration workflows. In fact, I’m going to use some basic workflows to set the computer name and IP configuration. First, I’ll verify remote connectivity.

Looks good. Next, I’ll define some PowerShell variables to use with my workflows.

The first workflow I want to run will perform some basic configuration.

Once this workflow is loaded into my session I can run it and configure the new server.

Next, I want to configure the IP configuration. The new server only has a single NIC which simplifies matters a great deal. Here’s the workflow I’m going to use.

To execute, I’ll splat a hashtable of parameters to it.

One caveat here is that when you change the IP address you’ll lose your connection to the remote computer. PowerShell will keep retrying. What I probably should have done was to include some parameters to limit the retry count. Eventually, the command will timeout and I can continue.

Next, I want to rename the computer and join it to the domain.

Again, I’ll splat a hashtable of parameters, this time connecting to the new IP address.

Eventually the computer will reboot and I’ll get a positive result.


Excellent. Now that the server has rebooted it belongs to the domain and I can use the new name to verify a few things.


I used the new server’s FQDN for the CIMSession name as I couldn’t get the NETBIOS name to work. Probably because I didn’t wait long enough for browser stats to get updated. Anyway, it works and I can also verify Hyper-V is working.


The last thing I should do is remove the trusted hosts settings on the client. But because I trust my network and I might need to do this again, I think I’ll leave it for now. But I did it! I now have a Hyper-V server ready for me to use.

Mini Hyper-V: Setup

Now that hardware has been installed on my mini Hyper-V project, next up is to setup the unit and get software installed. The Brix fires up very quickly and of course since nothing is installed I initially see the no operating system found message. Rebooting, pressing F2 gets me into the BIOS setup.


The only thing I need to do on the first page is to adjust the date and time. I was hoping I could change the Project name to something such as Mini Hyper-V, but it doesn’t appear that is possible. On the Advanced tab, I’ll want to enable virtualization.


You can see the Brix has a dual-core i7 processor. On the Advanced tab I can also verify the mSATA drive.


Checking boot options I see that the unit only sees the internal drive.


But the device supports EEFI and legacy boot options so I’m not expecting any problems. After saving my changes I even verified that F12 will bring up a boot menu, should I need it.

Next I need an operating system. I decided to try preview of Windows Server 2012 Hyper-V R2. I realize I’ll need to re-install when it is finally released. I don’t expect to run anything other than Hyper-V on this little box and Server Core keeps the footprint nice and small. But how do I get it onto the unit? Easy. I need to “burn” the ISO to a USB stick. To do that I’ll use the freeware, ISO to USB.

One thing I messed up initially, not really thinking, is that you need a decent size USB device. I foolishly started with 2GB only to realize I need at least a 4GB device.


The utility will reformat the USB device. The one I was using had some pre-existing files and I had to try a couple of times to get the process to work. I think the best approach is to delete any files first, or even “pre-format” the device first. But once I got through that hurdle after about 7 minutes I had a bootable USB device which I inserted into the Brix and fired up.

The unit immediately detected the USB device and started the installation process.


Excellent. I selected a custom install.


By the way, I’m installing without a mouse but the keyboard shortcuts are more than sufficient. Install is very speedy. Copying the install files too literally seconds. Of course I’m installing Server Core but still very impressive.


The overall installation took less than 3 minutes. Reboots are blazingly fast. Within minutes I had the initial screen to change the admin password.


After struggling to get a password typed on my super mini keyboard, I’m eventually rewarded with the Server Core setup windows.


I was wondering if I would need to load any drivers off the CD that came with the Brix, but so far I haven’t seen a need. I notice an occasional ripple in the video, but that could be an artifact from the ancient Dell monitor I’m using or the adapter. In any event it’s no big deal since once this is setup it is going to run headless anyway. The server got a DHCP address which is the most important element so I should be ready to start configuring the OS. I’ll cover that in the next post.

Mini Hyper-V: Hardware Build

So the parts arrived for my mini Hyper-V project. I have to say I’m really excited about this. Everything is so tiny! Here’s what I have to work with.


I have the Brix unit, a 256GB mSATA drive, 16GB of RAM and a video adapter. The Brix unit is amazingly small and fits in the palm of your hand. As you can see, it is not much bigger than a CD-ROM. Oh, and that white spot is actually a reflection from the ceiling light. The only thing on the top, aside from the label is a power button which will glow blue when on.


There is a single USB port on the front. Here’s the business end. Sorry it is a little out of focus but I think you get the idea.


Now to start assembling. All I need is a small phillips-head screwdriver. Turning the unit over there are 4 corner screws. In the upper right there is also a small knob. Turns out when you unscrew everything you use it as a handle of sorts to remove the bottom. Very nice.


The internals are pretty straightforward.


The slots at the top are for memory and the mSATA goes in the bottom. You slide it in to the slot.


It doesn’t lie flat. You need to screw it down.


Even though the drive has holes for 2 screws, the Brix only has one, but it seems to get the job done. Next, I slide in the memory. This is easier to do if you insert the stick that will be on the bottom. The sticks slide in and then lock into place.

Here’s the finished install.


All that remains is to screw the bottom back on. Here I ran into my first minor gotcha. The unit isn’t an exact square so the back can only go on a few ways. But it seemed to me that one way fit better. The bottom has a “This Side Up” label. I think the right way is to have that label pointing to the “back” ports. The Brix is designed to be mounted (it includes a mounting plate), but since I’m not going to do that I think I’m ok.

I hooked up the power and fired it up.


Wow. Other than the blue light on the power button there is no indication that the unit is running. There is a fan, but it is impossible to hear. And of course the mSATA is silent. It is stunningly quiet. I can’t wait to get this bad boy loaded.