This post cover the following:

  • An overview of the steps to create the parent virtual disk
  • A script to automate creation of child VMs with a differencing disk

Environment

My environment is a Windows 11 host running Client Hyper-V. The VMs are running Windows 11 Enterprise (Eval).
I’m using PowerShell 5.1 and haven’t tested on other versions of the OS or PowerShell.

Parent Disk creation

The following is a brief overview of creating the base image that becomes the parent disk.

  • Create a Hyper-V Generation 2 VM
  • Enable the TPM (Settings > Security)
  • Install Windows 11
  • During the OOBE phase, select Other Signin Options > Domain Join
  • Create a local user e.g. “Bob”
  • Log on as Bob and configure the system and software
  • NOTE: Install all software per machine or Sysprep will fail
  • Enable the built-in Administrator account and set the password
  • Log off from the Bob account and log on as Administrator
  • Delete the local profile for Bob’s account as follows:
$p = Get-WMIObject -Class Win32_UserProfile -Filter "LocalPath='c:\\users\\Bob'"
$p.Delete()
$p.Dispose()
  • Delete the local user account for Bob
  • Run Sysprep as follows:
c:\windows\system32\sysprep\sysprep.exe /generalize /oobe /mode:vm
  • Delete the VM in the Hyper-V console (the disk will remain)
  • Move the VHDX disk file to an appropriate location and set the NTFS properties to be read-only.

PowerShell Script

The script below creates a new VM with a Differencing Disk linked to the parent disk.
The main benefits of a Differencing Disk are:

  • Rapid deployment - only have to go through OOBE and you have a working OS
  • Save disk space - the base OS is in the parent disk

Example

New-DiffVM

Script



This article was originally posted on Write-Verbose.com