From cc17e92b2076c8bfed6ebc66a8ff42b2b021db22 Mon Sep 17 00:00:00 2001 From: Nils Arnold Date: Tue, 18 Mar 2025 12:40:16 +0100 Subject: [PATCH 1/2] Retry with local bcdboot.exe not only for old versions --- WinImageBuilder.psm1 | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/WinImageBuilder.psm1 b/WinImageBuilder.psm1 index 51a4186..a7226a3 100755 --- a/WinImageBuilder.psm1 +++ b/WinImageBuilder.psm1 @@ -274,18 +274,17 @@ function Create-BCDBootConfig { # Note: older versions of bcdboot.exe don't have a /f argument if ($image.ImageVersion.Major -eq 6 -and $image.ImageVersion.Minor -lt 2) { $bcdbootOutput = & $bcdbootPath ${windowsDrive}\windows /s ${systemDrive} /v - # Note(avladu): Retry using the local bcdboot path - # when generating Win7 images on Win10 / Server 2k16 hosts - if ($LASTEXITCODE) { - Write-Log "Retrying with bcdboot.exe from host" - $bcdbootOutput = & $bcdbootLocalPath ${windowsDrive}\windows /s ${systemDrive} /v /f $diskLayout - } } else { $bcdbootOutput = & $bcdbootPath ${windowsDrive}\windows /s ${systemDrive} /v /f $diskLayout } if ($LASTEXITCODE) { - $ErrorActionPreference = "Stop" - throw "BCDBoot failed with error: $bcdbootOutput" + # Retry using the local bcdboot path + Write-Log "Retrying with bcdboot.exe from host" + $bcdbootOutput = & $bcdbootLocalPath ${windowsDrive}\windows /s ${systemDrive} /v /f $diskLayout + if ($LASTEXITCODE) { + $ErrorActionPreference = "Stop" + throw "BCDBoot failed with error: $bcdbootOutput" + } } Reset-BCDSearchOrder -systemDrive $systemDrive -windowsDrive $windowsDrive ` From 4954f77aaa2cdd8964460aa4a762dd800cab8db3 Mon Sep 17 00:00:00 2001 From: Nils Arnold Date: Tue, 25 Mar 2025 10:56:42 +0100 Subject: [PATCH 2/2] Leave old retry part and add new one independently / fix indent --- WinImageBuilder.psm1 | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/WinImageBuilder.psm1 b/WinImageBuilder.psm1 index a7226a3..adb7cca 100755 --- a/WinImageBuilder.psm1 +++ b/WinImageBuilder.psm1 @@ -274,19 +274,24 @@ function Create-BCDBootConfig { # Note: older versions of bcdboot.exe don't have a /f argument if ($image.ImageVersion.Major -eq 6 -and $image.ImageVersion.Minor -lt 2) { $bcdbootOutput = & $bcdbootPath ${windowsDrive}\windows /s ${systemDrive} /v + # Note(avladu): Retry using the local bcdboot path + # when generating Win7 images on Win10 / Server 2k16 hosts + if ($LASTEXITCODE) { + Write-Log "Retrying with bcdboot.exe from host" + $bcdbootOutput = & $bcdbootLocalPath ${windowsDrive}\windows /s ${systemDrive} /v /f $diskLayout + } } else { $bcdbootOutput = & $bcdbootPath ${windowsDrive}\windows /s ${systemDrive} /v /f $diskLayout - } - if ($LASTEXITCODE) { # Retry using the local bcdboot path - Write-Log "Retrying with bcdboot.exe from host" - $bcdbootOutput = & $bcdbootLocalPath ${windowsDrive}\windows /s ${systemDrive} /v /f $diskLayout if ($LASTEXITCODE) { - $ErrorActionPreference = "Stop" - throw "BCDBoot failed with error: $bcdbootOutput" + Write-Log "Retrying with bcdboot.exe from host" + $bcdbootOutput = & $bcdbootLocalPath ${windowsDrive}\windows /s ${systemDrive} /v /f $diskLayout } } - + if ($LASTEXITCODE) { + $ErrorActionPreference = "Stop" + throw "BCDBoot failed with error: $bcdbootOutput" + } Reset-BCDSearchOrder -systemDrive $systemDrive -windowsDrive $windowsDrive ` -diskLayout $diskLayout