Skip to content

Instantly share code, notes, and snippets.

@dot-mike
Created December 16, 2024 19:57
Show Gist options
  • Save dot-mike/58ddf45b4d4939697fcc22460700ec66 to your computer and use it in GitHub Desktop.
Save dot-mike/58ddf45b4d4939697fcc22460700ec66 to your computer and use it in GitHub Desktop.
Hyper-V to create a new VM quickly from existing vhd file
$VMName = Read-Host 'Name your VM'
New-Item -Path C:\Hyper-V\ -Name "$VMname" -ItemType Directory -Force
Copy-Item -Path "C:\Hyper-V\W11DevEvalImage\WinDev2407Eval.vhdx" -Destination "C:\Hyper-V\$VMname\$vmname.vhdx" | Out-Null
New-VM -Name $VMName -Path C:\Hyper-V\$VMName -MemoryStartupBytes 8GB -VHDPath "C:\Hyper-V\$VMname\$vmname.vhdx" -Generation 2 -BootDevice VHD
Set-VM -Name $VMName -ProcessorCount 4
Set-VMMemory $VMName -DynamicMemoryEnabled $false
Set-VM -Name $VMName -CheckpointType Disabled
Connect-VMNetworkAdapter -VMName $VMName -SwitchName External
#TPM
$HGOwner = Get-HgsGuardian UntrustedGuardian
$KeyProtector = New-HgsKeyProtector -Owner $HGOwner -AllowUntrustedRoot
Set-VMKeyProtector -VMName $VMName -KeyProtector $KeyProtector.RawData
Enable-VMTPM $VMName
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment