VBScript to merge a differencing disk to a new file

VBScript to merge a differencing disk to a new file

  • Comments 3

Got an email the other day asking for a sample script on how to merge a differencing disk to a new file - so here we go:

   1: Option Explicit
   3: 'Define constants
   4: CONST vmDiskType_Dynamic = 0
   5: CONST vmDiskType_FixedSize = 1
   6: CONST vmDiskType_Differencing = 2
   8: dim vs, aVHD, aVHDFileName, newVHDFileName, vmTask
  10: 'Grab command line arguments
  11: aVHDFileName = WScript.Arguments.Item(0)
  12: newVHDFileName = WScript.Arguments.Item(1)
  14: 'Connect to Virtual Server
  15: Set vs = CreateObject("VirtualServer.Application")
  17: 'Create VHD object
  18: set aVHD = vs.GetHardDisk(aVHDFileName)
  20: 'Merge the VHD to a new dynamic disk
  21: if aVHD.type = vmDiskType_Differencing then
  22:    wscript.echo "Merging the VHD to a new file..."
  23:    set VMTask = aVHD.MergeTo(newVHDFileName, vmDiskType_Dynamic)
  24:    vmTask.WaitForCompletion(-1)
  25: end if

As you can see, this script take two command line parameters: the differencing disk and the target disk.  It then merges the differencing disk with its parent and stores the result in the new target disk.


Leave a Comment
  • Please add 2 and 8 and type the answer here:
  • Post
  • how does one allow for shared folders between Virtual PC 7.0.2 running DOS 6.22 with the host operating system OS X.4.8?

    I've got the DOS up and running under Virtual PC, but the "Install or Update Additions" button seems to do nothing.

    Any suggtions?

    Thanks in advance,

    Arun Chandra


  • Nice script Ben - now how do I get it to work on Server 2k8 R2, which complains that it can't access the ActiveX component?

  • What if I don't have Virtual Server installed ? is there any other alternatives ?

Page 1 of 1 (3 items)