Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Do not attempt to modify SecureBootTemplate on a VM with a vTPM initialized #137

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion builder/hyperv/common/powershell/hyperv/hyperv.go
Original file line number Diff line number Diff line change
Expand Up @@ -718,8 +718,10 @@ func SetVirtualMachineSecureBoot(vmName string, enableSecureBoot bool, templateN
var script = `
param([string]$vmName, [string]$enableSecureBootString, [string]$templateName)
$cmdlet = Get-Command Hyper-V\Set-VMFirmware
# We cannot modify SecureBoot Templates on VMs with a TPM enabled
$tpmEnabled = Hyper-V\Get-VMSecurity -VMName $vmName | Select-Object -ExpandProperty TpmEnabled
# The SecureBootTemplate parameter is only available in later versions
if ($cmdlet.Parameters.SecureBootTemplate) {
if ($cmdlet.Parameters.SecureBootTemplate -and !$tpmEnabled) {
Hyper-V\Set-VMFirmware -VMName $vmName -EnableSecureBoot $enableSecureBootString -SecureBootTemplate $templateName
} else {
Hyper-V\Set-VMFirmware -VMName $vmName -EnableSecureBoot $enableSecureBootString
Expand Down