Steps to Create a Windows Template
Assuming that the Windows Template guest VM has already been spun up and configured, the next step would be to “SysPrep” it prior to converting the image into a template.
Run: sysprep.exe > select Out-of-Box Experience > Generalize > Shutdown
Alternative command line:
%WINDIR%\system32\sysprep\sysprep.exe /generalize /shutdown /oobe
After the template VM has been shutdown from the previous move, navigate to the named target machine > right-click it > click Export… > Specify the exporting storage location > click Export to initiate the task
Once this exporting process completes, the original machine could either be retained for future update and re-export or deleted as the golden image has already been generated. Common practice is to leave the original image as-is.
A Punch of Clicks to Import a Template
Note: Hyper-V will make an exact copy of the chosen image during the exporting steps. Hence, it will be necessary to manually change the server name label, rename the disk(s), change the settings of the new VM to point to this newly renamed disk file
To rename the VM disk, navigate to C:\MSClusterStorage\Volume1\VHD\SERVER007\Virtual Hard Disks > right-click a desired disk file > rename (e.g. SERVER007.vhdx) > input a new name > press Enter
To Import an Exported VM, navigate to Hyper-V Manager > select the host where a new VM is to be deployed > right-click it > Import Virtual Machine… > select the correct folder and image file that has been generated by the previous export > at the Choose Import Type option, select “Copy the virtual machine (create a new unique ID)” radio button > specify the destination storage location for the new VM similar to an example below:
Virtual Machine configuration folder: C:\MSClusterStorage\Volume1\VHD\SERVER007
Checkpoint store: C:\MSClusterStorage\Volume1\VHD\SERVER007\Snapshots
Smart Paging folder: C:\MSClusterStorage\Volume1\VHD\SERVER007
Specify Virtual hard disks to use: C:\MSClusterStorage\Volume1\VHD\SERVER007\Virtual Hard Disks\SERVER007.vhdx
Click Import when done > navigate to the newly imported VM (that may have the same label as the original template) > right-click it > Settings… > verify that the Hard Drive is set at the correct location to confirm that it is indeed a new machine > set CD Rom attached ISO to ‘none’ > OK > right-click the imported machine again > rename > input a desired name for the new machine > press Enter to make the renaming function effective > right-click the renamed VM > Start > right-click it once more > connect > Access the console of the running VM to proceed with OS reconfigurations
Note that the networking aspects are reset during sysprep, thus it would be necessary to run ncpa.cpl to reconfigure IPV4 properties of the newly created Windows VM.
Alternative, there is a PowerShell script to perform the steps above: https://gallery.technet.microsoft.com/scriptcenter/To-create-a-virtual-190affb3
Me now considering a fork of that script and add some new features… Until then…