This blog will show you my self built PowerShell based Hyper-V Manager for my work laptop. I work as an IT consultant at Advantive. During my work I do have the need for testing things on virtual machines running Windows Server or Windows 10/11 client OS.
The built in Hyper-V works perfect for this. It only lacks an easy way of deploying templates of Windows OS images. Therefore I created a PowerShell based Hyper-V Manager that does exactly this. The script works on Windows 11, but should also work on Windows 10 or even Windows Server.
Download the script from this link: LocalHyperVManager_v20241201.zip
Features of my solution:
- Save disk space due to VHDX differential disks.
- Deploy new Windows based VM with default size and default settings in just a minute.
- Allow connectivity from Hyper-V host to VM with an Internal Network, for example to use RDP to enter the VM.
System Requirements
- Modern Intel or AMD CPU that allows Hyper-V to work.
- Windows 10, 11 Pro or Windows Server 2016 or higher.
- 16 GB will work, but 32GB or more memory recommended. (the memory is for the Hyper-V Virtual Machines)
- SSD disk with at least 100GB or more free. (more VMs means more space is required)
- My setup has an 127GB OS disk, and a 200GB Hyper-V disk. This can be two physical SSDs or 1 SDD partitioned.
We need a few steps to get this to work.
- Enable the Hyper-V role on Windows 11
- Create the folder structure
- Configure the script
- Configure Hyper-V network
- Test the script
- Create VHDX templates
1. Enable the Hyper-V role on Windows 11
Login with Admin permission on you Windows 11 laptop.
- Press the Windows key + R to open the Run dialog box.
- Type appwiz.cpl and press Enter.
- In the Programs and Features window, select Turn Windows features on or off in the left-hand pane.
- In the Windows Features window, scroll down to Hyper-V and check the box next to it.
After the installation your machine has to reboot.
2. Create the folder structure
In my setup I use this folder structure:
Folder | Description | |
D:\Hyper-V | Hyper-V root folder | |
_Scripts | Scripts | |
_Template | VHDX templates | |
D:\ISO | Contains ISO files of Windows Server / Client |
3. Configure the SCRIPT
The script comes with an XML file with all settings in it. You can edit this file with Notepad or other text editors.
Setting | Description |
Config\Paths\Templates\Folder | Add one or more paths where you want to store the templates. |
Config\Paths\HyperVRoot | Single path, in this folder the new VMs are stored. |
Config\HyperVSettings\DefaultSwitchName | Name of the switch that is connected to all new VMs by default |
Config\HyperVSettings\ExtraSwitchName | If you want a VM to have 2 switches, this is the second switch connected. |
Config\VMSettings\CPUCount | Default number of CPUs for a new VM. |
Config\VMSettings\Memory | Default memory size for a new VM. |
Config\VMSettings\OSDiskSizes | Default OS disk size for a new VM. |
4. Configure Hyper-V network
Start Hyper-V manager from the Start Menu
Click “Virtual Switch Manager…”
Create a new Internal Virtual Switch called: LABLAN (or another name you prefer).
Next we need to give the network card an IP on the HOST.
- Press the Windows key + R to open the Run dialog box.
- Type ncpa.cpl and press Enter.
- Right click the LABLAN vEthernet interface, click properties and click Internet Protocol Version 4 (TCP/IP), click properties
- Enter a static IP without a default gateway, for this example I use:
IP Adress: 10.150.10.254
Subnet Mask: 255.255.255.0
5. Test the script
Run the script from PowerShell ISE or another method. I created a shortcut on my desktop to start the script. Make sure you run it with Admin permissions (elevated).
Options
Nr | Option |
1 | With the help of an interactive menu, create new VM from a template. |
2 | Create a new VM with an empty disk. |
3 | Delete an existing VM |
4 | Toggle the Nested Virtualisation setting. |
5 | Show an overview of VMs |
Q | Quit |
6. Create VHDX templates
When you put your template VHDX files in the template folder give them a name you recognize for it’s purpose. Just “os.vhdx” is not that explanatory.
I use this format:
- Win2022_gen1_en_20241025.vhdx
- Win11_23h2_gen2_nl_20240928.vhdx
Note the gen1 and gen2 addition. For templates you need to put these in the name. The script will create the VM type according to the gen1 or gen2 part in the name. You can create the VHDX file in any name you like and just rename it when you put it in the templates folder.
Short version
The short version of creating templates:
- Create a new VM with empty disks.
- Attach the ISO of the OS you would like to install.
- Install the OS, change settings like timezone, enable RDP, install software etc.
- SYSPREP the machine (OOBE, Generalize, Shutdown).
- Copy/Move the VHDX to the Templates folder and rename as suggested before.
Long version
Now we create the VHDX templates. This example is created with the Preview version of Windows Server 2025. Download your ISO to the D:\ISO folder.
We need to create a new VM, let’s do it with Local Hyper-V Manager
Start the script:
The creation of the VM will take a few seconds. You can now exit the menu.
Open Hyper-V manager and find the new VM, we need to attach the ISO file now.
Click “SCSI Controller”, DVD Drive and Add
Click “Image file” and “Browse”, browse to the ISO file of your choosing and click Apply.
Change the boot order like in the picture. DVD Driver first, next Hard Drive then the Network Adapter. Click Apply.
Click “Checkpoints” and disable “use automatic checkpoints”. Click OK.
Right click the VM and click Start. Right click the VM and click Connect. The VM is booting, install the OS like you would do on a physical PC, in this case “press any key to boot from CD or DVD ….”
I will skip the install of Windows Server, just follow the wizard and finish the setup. I always customize the base image a little. I adjust the timezone, and enable RDP before I sysprep the machine.
Open an elevated Terminal / PowerShell / CMD
Type this command: cd \windows\system32\sysprep
Then type this command to start sysprep: .\sysprep
In the sysprep tool, select OOBE, enable Generalize and choose Shutdown Option “Shutdown”. Click OK.
Let sysprep do it’s magic and wait for the machine to shutdown.
When the VM shut down, we need to cut & paste the VHDX to the D:\Hyper-V\_Template folder.
Next we rename the VHDX file:
I use this naming convention: Win<version>_gen?_<lang>_<date>.vhdx
For example: Win2025_gen2_en_20241006.vhdx
Make sure you set the correct _gen?_ part in the name, the script uses this to create a correct VM from the template.
You can now delete the Virtual Machine and remove the folder structure from the template machine. D:\Hyper-V\win2025-template
As you can see in the screenshot below, the file is renamed, and I added a few other templates.
7. Use the script
Create new VM from template
Start the script again.
When you choose option 1 “Create new VM from template” you will see all template files found in the template folders. You can then choose the network options and the name and reason for this VM.
After it’s creation you will get a summary of the creation process.
When you go to the settings of the new VM you will see the reason mentioned in the Management/Notes part of the VM. It tells you when the VM was created, what the differential source file is and what the reason was. I strongly suggest you enter a reason, because I found myself looking for why ooh why did I create this VM.
Tip: If you put [PRODUCTION] in the notes part, the delete option in the script will not allow you to delete the VM.