I have multiple Virtual Machines I am to build from a Sysprepped VHDX. (All this is done automatically via Powershell)
For each of these Virtual Machines, I copy this VHDX and create a new one unique to the Virtual Machine. However, I wish to mount each one (in parallel) and make modifications before attaching it to the virtual machine and booting the first time.
The issue comes when it is time to mount the VHDX on the Physical Host, and these two processes attempt to mount at the same time. This causes a Signature Collision. I am looking for a clean - emphasis on clean - way to prevent signature collision. I have tried the following.
Using the Get-Drive cmdlet and determining if one exist with a FriendlyName of "Microsoft Virtual Disk" before mounting, to detect if another VHDX is already mounted and waiting til it dismounts - the latency in this flag being available causes this method to fail and still the two VHDXs attempt to mount and have signature collision, breaking the script associated with that VHDX.
I have tried using a Flag file, i.e., a text file to denote if a VHD is mounted and do a similar check - however, this relies on the file system and seems too clumsy for me.
I have considered Environment variables, but am afraid this is also too convoluted for such a simple task.
Any recommendations?