From 46a5aad2a1e81a8beb2af1e52166c1a8524fc813 Mon Sep 17 00:00:00 2001 From: Arunesh Dwivedi Date: Fri, 5 Jun 2026 08:32:59 +0000 Subject: [PATCH] fix: skip default restart check when custom restart_check_command is provided When a user provides a custom restart_check_command to the windows-restart provisioner, the DefaultRestartCheckCommand (which uses [System.Net.Dns]::GetHostName()) was still being executed afterward. This breaks Windows Constrained Language Mode because that .NET call is not allowed in constrained mode. Fix: when a custom restart_check_command is provided, skip the default PowerShell module-load check entirely. The user's custom command is sufficient to verify the restart. Fixes hashicorp/packer#13643 --- provisioner/windows-restart/provisioner.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/provisioner/windows-restart/provisioner.go b/provisioner/windows-restart/provisioner.go index ea3090244c3..5ffb0778739 100644 --- a/provisioner/windows-restart/provisioner.go +++ b/provisioner/windows-restart/provisioner.go @@ -210,10 +210,7 @@ WaitLoop: } var waitForCommunicator = func(ctx context.Context, p *Provisioner) error { - runCustomRestartCheck := true - if p.config.RestartCheckCommand == DefaultRestartCheckCommand { - runCustomRestartCheck = false - } + runCustomRestartCheck := p.config.RestartCheckCommand != DefaultRestartCheckCommand // This command is configurable by the user to make sure that the // vm has met their necessary criteria for having restarted. If the // user doesn't set a special restart command, we just run the @@ -236,7 +233,9 @@ var waitForCommunicator = func(ctx context.Context, p *Provisioner) error { continue } log.Printf("Connected to machine") - runCustomRestartCheck = false + // User provided a custom check — skip the default PowerShell + // module-load check to avoid breaking Constrained Language Mode. + break } // This is the non-user-configurable check that powershell // modules have loaded.