← script library

Automating Hyper-V Virtual Machine Creation

Hyper-VJanuary 9, 2025

Today, we are sharing a script that automatically creates a new virtual machine in Hyper-V. This simplifies your workflow, making it easier to manage your virtual environments.

powershell
$VMName = "NewVM"
$VMMemory = 2GB
$VMDiskSize = 20GB
$VMSwitch = "VirtualSwitch"

New-VM -Name $VMName -MemoryStartupBytes $VMMemory -NewVHDPath "C:\Hyper-V\$VMName\$VMName.vhdx" -NewVHDSizeBytes $VMDiskSize -SwitchName $VMSwitch

Set-VMProcessor -VMName $VMName -Count 2
Set-VM -VMName $VMName -AutomaticStartAction StartIfRunning
Enable-VMIntegrationService -VMName $VMName -Name "Guest Service Interface"

Start-VM -Name $VMName

Run it across your fleet

This script runs as-is on a single host. Paste it into ServerEngine to schedule it, run it on a whole server group in parallel, and keep the credentials out of the file — see the scripts documentation and the credential store.

Ready when you are.

Try ServerEngine free for 7 days.