'Creating a Hyper-V VM using Powershell as a Generation 2 with TPM and DVD not working
I have a script which is working fine if I create a Hyper-V VM with no specific generation listed (defaults to Gen 1). I have a custom boot image that it loads fine and everything works.
I needed to update it to Generation 2 and enable TPM for Windows 11. Everything the same, just changing to -Generation 2 in the New-VM line and it no longer adds the VMDVD drive, nor does it set my Network Bridge. If I remove -Generation 2 all is fine again (but no TPM, so Win 11 won't work)
Current code :
New-VM -Name "$fs" -Generation 2 -MemoryStartupBytes 4GB -NewVHDPath c:\PrgoramData\vmconfig\$fs.vhdx -NewVHDSizeBytes 100GB
Set-VMDvdDrive -VMName $fs -Path "C:\hyperv\hyperv.iso"
#Also setting TPM, if not Gen2, this isn't there
Set-VMKeyProtector -VMName "$fs" -NewLocalKeyProtector
Enable-VMTPM -VMName "$fs"
Works fine if the -Generation 2 is not there.
Looking for thoughts on how to fix that
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
