Build and Restore Snapshots in Hyper-V with Windows PowerShell

Microsoft Scripting Guy, Ed Wilson, is here. If you are a seasoned Hey, Scripting Guy! Blog reader, you know that the most frequent guest blogger is Sean Kearney. If you are new to the blog, I welcome you, and I encourage you to catch up with Sean’s previous blogs.

With Microsoft TechEd Europe and a few other presentations on the horizon, I was thinking about how nice it would be have my environments self manage for the demos.

Typically with most demos in a virtual environment, you make a snapshot of everything in the Gold setup. Then when you enter into your presentations, you can immediately roll back to the original configuration to prepare for your next presentation.

Or perhaps you’re firing up a test environment, and you need to be able to take a snapshot and restore sets of machines to troubleshoot a package issue.

With Windows Server 2012 and the new Hyper-V module, this is as natural as breathing.

Let’s say we have a list of virtual machines in our environment: a domain controller, a SQL Server, and perhaps our web application. We’ll name them DC1, SQL1, WEB1. Although these are the NetBios names, for convenience I have given them the same names in Hyper-V.

$VMNames=”DC1”,”SQL1”,”WEB1”

To create a checkpoint on the virtual machines, we can simply use the Checkpoint-VM cmdlet and run it like this:

CHECKPOINT-VM –Name DC1 –Snapshotname ‘Base’

This will not only create a snapshot, but it will have a unique name that we can refer to. To run this against a list of machines, we can pipe the list by using Get-VM or supply a list like in our variable:

$VMNames | GET-VM | CHECKPOINT-VM –SnapshotName ‘Base’

This will create a snapshot named “Base” on the virtual machines named DC1, SQL1, and WEB1.

If we’d like to access all of these snapshots, we can run this command:

is there a way like this to create/restore checkpoint in Windows 2008 R2 Hyper-V environment? This is cool blog article but without Microsoft's new Hyper-V cmdlet such as Get-VM, Checkpoint-VM, what we should do in older version of Hyper-V and PS? Thanks.