Resources, Scripting, Server 2008 R2, Windows
comments 2

Script to automate creation of OS VHDs from Server 2008 R2 media

I have been working with the public beta of Windows Server 2008 R2 and have been exploring quite a few features of this new release. It costs a lot to the people to publish a version of beta, and it majorly is due to the data storage expenses. Here’s how much businesses spend on servers. But of Course, native VHD boot is one of them. On my home PC, I have R2 Enterprise edition with AIK tools to capture OS in to VHDs whenever I need. However, I find this process of manually capturing VHDs a bit time consuming and repetitive task. So, decided to automate it so that I can do something else while the VHD creation is in progress. Here is the script if you are as lazy as me 🙂

What this script does is simple. You need to unzip the downloaded zip file to some location on your computer and at the command prompt, just run cscript captureVHD.vbs /src:<DVD Drive Letter>. For example, on my system, C:\> cscript c:\scripts\captureVHD.vbs /src:D:

This, depending on the OS DVD (Windows 7 or Server 2008 R2 only) you have, will display a menu as shown here.

VHD Capture Menu

VHD Capture Menu

All you need to do is enter the number against one of the images listed there or just enter A or a to capture all images as VHDs. This takes a few minutes to complete and copies all VHDs to %systemdrive%

Some known issues

1. Windows AIK path is hard coded in the script. You may have to change it if you did not install Windows AIK at the default path or your %systemdrive% is not C:

2. Size and type of the VHD will be 40GB and Dynamic respectively. This is, currently, not a configurable option. You can change the script to suit your needs.

3. This script always copies the VHDs to %systemdrive%

4. VHDs captured using this method cannot be conected to a Hyper-V VM directly. You will have to follow a few steps mentioned in this post

Here is the link to script download

Filed under: Resources, Scripting, Server 2008 R2, Windows


Ravikanth is a principal engineer and the lead architect for Microsoft and VMware virtualized and hybrid cloud solutions within the Infrastructure Solutions Group at Dell EMC. He is a multi-year recipient of Microsoft Most Valuable Professional (MVP) award in Windows PowerShell (CDM) and Microsoft Azure. Ravikanth is the author of Windows PowerShell Desired State Configuration Revealed (Apress) and leads Bangalore PowerShell and Bangalore IT Pro user groups. He can be seen speaking regularly at local user group events and conferences in India and abroad.