In this article, I will show you how to create Hyper-V VM template to prepare the VM after imaging and then export and import it as a template on Hyper-V 2022, with a Server 2012 Datacenter VM.
Creating a Hyper-V template to rapidly deploy new virtual machines can save time on spin-up and updating. We can establish Hyper-V templates pre-installed with Windows features and programs just as a WDS or PXE image would produce a consistent configuration for every deployment.
Create Hyper-V VM Template
First, we will create a VM template. Right-click on Hyper-V host, choose new, and then virtual machine.

Choose next.

Specify the name and location and then choose next.

Specify generation and choose next.
Additional information about virtual machine generation is located here.

Assign virtual machine template memory and then click next.

Again a network and choose next.

Connect the virtual hard disk page, assign storage size for VM, and select next.

Configure installation options and choose next.

Verify the new virtual machine summary and then choose the finish.

Now proceed with the installation of the operating system as you would any other server. Once OS installation is done. Do not join the domain or activate it. This data will be cleaned during the Sysprep action we will be taking next. You can change the virtual machine name which will also be reset.
Sysperp Preparation Tool
Once you have your apps, settings, and updates where you want them on the virtual machine, go to C:WindowsSystem32SysPrep and then run SysPrep.exe

You will need to use the individual experience and check the box to Generalize. In the shutdown options, choose shutdown. The system will enter into a generalized state much like when purchasing a system from a retailer and shutdown once done so we can export the template.

Once your virtual machine is completely shut down, right-click on it and then choose export.

Create Hyper-V VM Template
Select your Export Location and Click Export
Optionally, simply you can copy and paste the VM template VHD and rename it each time you stand up a new VM. Selecting the export option permits for sharp cloning of the VM Configuration file, which might prove helpful if you plan to set up numerous virtual machines with the same hardware specs.

Now Hyper-V will go through the method of copying the VM hard drive and configuration to the target you selected. Once the copying process is done, you can move the exported directory to any other Hyper-V server running a similar version as where you created the virtual machine and import the image for use.
You can leave the VM and turn it on later to apply the updates and repeat the Sysprep method to keep an always up-to-date Hyper-V template.
Importing the virtual machine template looks just as simple as exporting the VM, but there are a few additional items that need changing after import.
Right-click on Hyper-V host and then choose import.

Import virtual machine, choose next.

Click on the browse button to select the exported template VM.

Select the template folder and then choose open.

Click next.

Select the virtual machine and choose next.

Tick the box Copy the virtual machine to create a new ID and click next.

Specify the directory of the VM files after the copy and the directory of the VHD. Click next

Choose the storage folder and click next.

Verify the importing VM summary and then choose the finish.

Virtual Machine Settings
Do not forget to edit the virtual machine after renaming the disk and remap the virtual disk to this new file name.

After that, it’s simply powering the VM on, going through the initial setup, and you have a fully updated virtual machine that’s been deployed in a few minutes.


