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.


Easy VM Backup with Veeam Zip

If you run a small VMware or Hyper-V setup, perhaps for a lab or personal training, you probably haven’t thought to much about backing up your virtual machines. But it is actually pretty easy and doesn’t cost anything. Let me give you a quick intro to the free backup tool from Veeam. The first thing you need to do is download it. The install is pretty straightforward so I’ll skip that part.

When you fire it up for the first time you’ll see a tree for VMware and Hyper-V. This product works for both! Right-click on whichever virtualization infrastructure you are using and add a server. It is a quick and easy wizard that should only take a minute to complete. The app should automatically enumerate all the virtual machines.


To create a backup right-click on a virtual machine and select Veeam zip, or you can use the menu icon. You will be ask to provide a path for the backup.


The program will create a single zip file of all associated files for the virtual machine. It takes a few minutes for the backup to get up to speed.


Eventually my backup reached 24MB/second. When the backup finishes you can view a status report by going to History and then right-clicking on the backup. You can view stats.


Or a summary report as an HTML file in your browser


All of the files will be stored in a vbk file. This is a zip file format. You can extract files locally, or leave it alone until you need to restore something.

There are some limitations, but remember this is a free tool not a free trial. There’s no PowerShell support and it doesn’t support Hyper-V on Windows 8. Those are biggies for me. Of course Veeam has a full-blown backup product that you should try out, especially if you like the idea of managing backups via PowerShell.

I’ll cover some additional features in future posts.

Surviving the Zombie Apocalypse

I got this announcement the other day for a Halloween webinar and the title is just too cool not to share: “Surviving the Zombie Apocalypse: Protecting Both Your Brains and Your Data.” I hope it goes without saying that data protection is a big part of an IT Pro’s job so anything we can learn is an asset. This webinar uses the zombie apocalypse as an effective metaphor for data management.

  • On the defense. Zombies not only go after the biggest brains, but the most data as well, so deduplication is critical.
  • On the run. Remember, you don’t have to run faster than the zombies, you just have to run faster than the other IT people. Use all-in-one backup, archiving, and disaster (zombie) recovery appliances to stay ahead of your peers.
  • Living in an undead world. Even if zombie overlords rule the planet, cash will still be king. Make every dollar count by ensuring that your backup vendor isn’t nickel and diming you to death. Because death isn’t an option in an undead world.

The free live webinar is on October 31 at 12:30 PM EST. Learn more and register at here.

Get GPO Backup

The GroupPolicy module from Microsoft offers a great deal of functionality from a command line. In terms of regular maintenance or administration it is pretty hard to beat, especially if you have 100s or 1000s of GPOs. When you have such a large number, backing them up is critical and easy to accomplish with the Backup-GPO cmdlet. However, if you want to restore or import from a backup, you have to resort to the graphical Group Policy Managment Console. I couldn’t find any way to manage GPO backups from PowerShell so I wrote my own.

My function, Get-GPOBackup, will search a GPO backup folder and retrieve backup objects. All of this is done using the file system. Technically you don’t need the Group Policy module to retrieve the backup information. However, if you want to restore anything then you of course need the Group Policy module loaded. The only parameter you need to specify is the path. Although the function is designed to use the value of a global variable, $GPBackupPath. So if you use this alot, set that variable. But perhaps before we get too far you’d like to see the function.

The complete function has comment based help.

get-gpobackp help
get-gpobackp help

As I said, the -Path parameter is key. It is not mandatory in the attribute-sense, but I have code that prompts for a missing value and the path is tested before anything else is done.

GPO backups are stored under a GUID for each GPO, so I use a regular expression pattern to identify these. I’m making an assumption that the path you specify won’t have any other folders with GUID-based names.

Each backup consists of a few XML files. My function parses the XML and creates a custom object for each backup. These are added to a temporary array.

Now for the really fun part. The function supports a few other parameters that allow you to search for a GPO by name. So if you specify -Name, everything else is filtered out.

I also include a parameter to get the latest backup. I accomplish this by grouping the backup objects by their GPO GUID, sorting by backup date and selecting the latest one.

You should end up with an object like this for each GPO backup.

I tried to create an object so that if you wanted to restore a GPO you could with minimal effort. Unfortunately, the Import-GPO cmdlet doesn’t have enough support for parameter binding. So if you want to restore a backup, you’ll need to resort to a ForEach-Object command like this:

My function is in a stand-alone script so to use it, you either need to copy and paste the function into your profile or dot source the script. Even though I wrote it to help with imports, you could easily use it to manage a backup folder, deleting obsolete backups. The function is writing an object to the pipeline that you can use in whatever manner you can think of. I hope you’ll let me know what you think and if there is anything you think is missing.

Download Get-GPOBackup.


Earlier this year I wrote an article for REDMOND Magazine about the new backup features in Windows Server 2008 R2. I’m not going to re-hash the article here except to say it includes some sample scripts on using the WBADMIN command line tool. One of the scripts is an old-school batch file.

The batch file included code to create a directory that included a time stamp, like \\mycompany-dc01\backup\RESEARCHDC\12152009_132532 where the last portion is the month, day, year, hour, minute and second. My original code parsed out these values from the %TIME% variable.

Unfortunately, I forgot to take into account situations where the time mght not have two digits like 1:00AM. In those situations the code tries to create a folder like \\mycompany-dc01\backup\RESEARCHDC\12152009_ 10000 which fails because of the space. To correct this I needed to add a line to check for the space in the variable, %h% and if found, define a new value with a leading 0.

This sort of thing is much, much easier in Windows PowerShell, by the way. But regardless, I now have an updated batch file.
[cc lang=”DOS”]

You can download the batch file here. Rename it to .bat.