Advertisement
guyrleech

Create Hyper-V VM from Template

Oct 4th, 2024
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ## Create new Hyper-V VM from a template (a SysPrep'd VM with no spanshots) by copying disk to new VM name , creating it and starting it
  2. ## Put the name of the virtual network switch in to connect to - in this example it is "External"
  3. ## Note that this line uses a V: drive for the VMs
  4.  
  5. $name='GLHVS22RAS20TP1' ; md V:\VMs\$name && cp 'V:\VMs\Virtual Hard Disks\Server 2022 template.vhdx' "V:\VMs\$name\$name.vhdx" -Force:$false && ($vm=New-VM -Name $name -SwitchName "External" -VHDPath "V:\vms\$name\$name.vhdx" -Generation 2 -MemoryStartupBytes (2GB) ) && Set-VMProcessor -Count 2 -VM $vm && Set-VMMemory -MaximumBytes (4GB) -DynamicMemoryEnabled $true -VM $vm && Add-VMDvdDrive -VM $vm && Start-VM -VM $vm
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement