In the previous post, I showed you how to get Hyper-V running on your Windows 10 computer. Next, we will create our first VM and then use it to quickly create additional VMs in the future. Before continuing, make sure you have an ISO of Windows 10, or if you have an SCCM or MDT environment, you can build a Hyper-V VM using that infrastructure.

Step 1: Reference VM Creation

If not still open from the last post, launch Hyper-V Manager.

In the Action Pane, click New -> Virtual Machine…

In the New Virtual Machine Wizard, click Next on the Before your Begin page, and on Specify Name and Location, give the VM the intended name.

Notice the Location section says C:\VMs? Even with this set, by default the VMs disk and configuration files do not get stored a subfolder of the VM name. However, if we simply select the box that says, “Store the virtual machine in a different location,” the wizard will create a folder with the VMs name and place the configuration and VHDs in that folder. Once these have been set, click Next.

For the Specify Generation page, make sure to select a Generation 2 VM. This will allow UEFI, SecureBoot, Enhanced Console Session (like copy/paste functionality), and supports GPT.

On the Assign Memory page, assign the VM 4GB of memory (4096MB) if you have sufficient resources…otherwise adjust accordingly. You can also utilize Dynamic Memory for your test machine if you wish. This will adjust the amount of memory provided to the VM based on demand, however will consume additional CPU resources to manage this effort.

The installation of Hyper-V on Windows 10 created a Default Switch. This will provide the machine with access to the internet.

On the Connect Virtual Hard Disk page, we will accept the default selection to create a new disk, with the default path.

For Installation Options, the selection will differ depending on whether you’re using SCCM, MDT, or an ISO file. Typically, environments with SCCM will use a network-based installation server, whereas MDT may either use an ISO file of the boot media or an installation server.

After we’ve populated an installation source, click Finish. Your VM will be created and listed in Hyper-V Manager under Virtual Machines. Double-clicking the VM will return the following console view:

Step 2: Install Windows and Generalize

Go ahead and click Start. As soon as the VM powers on, you will likely have to push a key to initiate the imaging process, then proceed to install Windows normally. If it asks for a product key during the install, click the option that says “I don’t have a product key.” When Windows is finished installing, it will provide you with some options, the first being region selection. This is known as Mini-Setup, or the Out-of-Box Experience (OOBE).

At this point, we’re going to press Shift + F10 on the keyboard, which will bring up a Command Prompt. Type SysPrep\SysPrep.exe and hit Enter.

This will launch the System Preparation Tool. In this application, we want to select the Generalize Option, and select Shutdown under the Shutdown Options, then click OK.

This process will prepare the installation for redistribution. It should only take a minute or so, then will shut down the VM. After it has powered off, go back into Hyper-V Manager.

In the Checkpoints pane, we will see that an automatic checkpoint was created when the VM was started. We need to delete this checkpoint, which will merge the files together. To perform this action, select Automatic Checkpoint, and choose Delete Checkpoint… from the right-hand Action Pane. When the warning message appears, choose Delete.

As the disk files are merged, the process will be reflected in Hyper-V Manager. Wait until the merge completes before proceeding.

Step 3: Build the Quick Create template

After the merge is finished, open File Explorer, and navigate to C:\VMs\CheckYourLogs01, or whatever you called the VM, and then open up the Virtual Hard Disks folder. Locate the .vhdx file, and copy it. Paste the file on a network share (it should be about 10GB in size), and don’t forget where you copied it!

While waiting for the .vhdx to copy over, let’s capture the SHA256 hash for the file, as we’ll need it later. To do this, launch a PowerShell session, navigate to the local folder where the .vhdx file is stored, and type the following command:

Get-FileHash -Path .\CheckYourLogs01.vhdx -Algorithm SHA256

This will take a few minutes, but we can still move on. Launch a Notepad window (or your favourite editor) and paste in the following, updating for your proper file name and hash value:

{
  "images": [
   {
      "name": "Windows 10 x64 Professional",
      "version": "1903",
      "locale": "en-US",
      "publisher": "Microsoft, Inc.",
      "lastUpdated": "2019-03-31T17:00:00Z",
      "description": [
        "Windows 10 x64 Pro 1903 Base Install." 
      ],
      "disk": {
        "uri": "\\\\QNAP\\Public\\CheckYourLogsVM.vhdx",
        "hash": "sha256:AF896229436754CC90FECA670DBFE54BAE6A3EE89FF63E459EDC711827A4723F"
     }
    }
  ]
}

Note in the file above that UNC locations have double the amount of blackslashes. This is how the language is written and is not a typo. Save the file in the same network location with a .json extension. My file is called CheckYourLogsVM.json, for example.

The final step is to point the Quick Create Gallery to our network share. To do this, go into the Windows Registry and navigate to HKLM\Software\Microsoft\Windows NT\CurrentVersion\Virtualization.

Create a new Multi-String Value called GalleryLocations and the path to the JSON file for the data. In my case, it’s \\QNAP\Public\CheckYourLogsVM.json, so the result looks like this:

If you want to deploy this registry setting out, or would rather keep the default Developer Edition location, you can use a script to populate it. Lars Iwer from Microsoft posted an article where you can grab it here.

On this machine, if we click the Quick Create button now, we see the following:

To make the selection screen a little prettier, we just need to modify the JSON file. Lars’ example in the aforementioned blog post shows you how to add PNG files for the image.

Hope this helps!

É