Coding Stephan

Hyper-V template for Intune

Want to test out autopilot device preparation in Hyper-V, but don’t know where to start? In this post, I’ll take you through the steps needed to create a Hyper-V virtual machine template for Intune.

Windows 11 Out-of-box-experience

Prerequisites

  • Windows 11 or Windows 10 (pro or enterprise)
  • Hyper-V installed
  • Windows 11 ISO (pro or enterprise), with at least the may 2024 updates

Create a new virtual machine

  1. Open Hyper-V Manager
  2. Click on Action and then New and Virtual Machine
  3. Click Next
  4. Choose a name for the virtual machine, for example, IntuneTemplate
  5. (optional) Choose a different location for the virtual machine
  6. Click Next
  7. Choose Generation 2
  8. Click Next
  9. Assign at least 4GB of memory, (more is probably faster)
  10. Click Next
  11. Select the virtual switch you want, I picked Default Switch
  12. Click Next
  13. Create a new virtual hard disk, size needs to be at least 30 GB, change the location if needed
  14. Click Next
  15. Install an operating system from a bootable image file, select the Windows 11 ISO
  16. Click Next
  17. Click Finish
  18. Right-click on the new virtual machine and click Settings
  19. Go to Security and enable Enable Secure Boot and Enable TPM (needed for autopilot)
  20. Click OK
  21. Right click on the virtual machine and click Connect
  22. In the new window, click on Start and press any key to boot from the ISO
  23. Install Windows 11 as you would on a physical machine (next, next, …)

Don’t go through the OOBE (setup steps)! instead continue with the next step in this guide.

Prepare the virtual machine

You virtual machine should now be in the Windows 11 setup screen, where you can pick your region.

  1. Press Shift + F10 to open a command prompt
  2. Run the following commands to prepare the virtual machine for autopilot:
cd c:\Windows\System32\Sysprep
Sysprep.exe /oobe /generalize /shutdown /mode:vm

This will prepare the machine to be able to be cloned. When this command finishes it will shut down the virtual machine.

Don’t start the virtual machine again! Instead, continue with the next step.

Convert the disk

  1. Open Hyper-V Manager
  2. Select the virtual machine you just created
  3. Click Edit Disk
  4. Click Next
  5. Locate the virtual hard disk file you created earlier
  6. Click Next
  7. Select Convert and click Next
  8. Choose VHDX and click Next
  9. Choose Dynamically expanding and click Next
  10. Choose a location for the new disk, and click Next
  11. Click Finish

Template created

You now have a disk image that you can use to create new virtual machines that will start in the OOBE (setup) screen.

All done!

Create a new virtual machine from the template

I’m not going to explain how to create a new virtual machine from this template as Steven Weiner has already created a great video on this topic.

His script is available in his GitHub repository.

Conclusion

You now have a Hyper-V template that you can use to test autopilot device preparation. Since this template is generalized, you can create multiple virtual machines from it.