Created
December 16, 2024 19:57
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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