From 59e247c012022c3066e7dac781eff75aa1c9f075 Mon Sep 17 00:00:00 2001 From: rbalsleyMSFT <53497092+rbalsleyMSFT@users.noreply.github.com> Date: Wed, 6 Aug 2025 15:56:21 -0700 Subject: [PATCH] Fixes LocalAccounts module issue in PowerShell 7 Applies a workaround for an issue where the `Microsoft.PowerShell.LocalAccounts` module fails to load in PowerShell 7 on Windows 11 23H2 and earlier. The script now checks the OS build number and imports the module using the Windows PowerShell compatibility layer on affected systems. Fixes: https://github.com/PowerShell/PowerShell/issues/21645 --- FFUDevelopment/BuildFFUVM.ps1 | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/FFUDevelopment/BuildFFUVM.ps1 b/FFUDevelopment/BuildFFUVM.ps1 index 11812b7..8adb36f 100644 --- a/FFUDevelopment/BuildFFUVM.ps1 +++ b/FFUDevelopment/BuildFFUVM.ps1 @@ -2542,6 +2542,14 @@ function New-FFUVM { Function Set-CaptureFFU { $CaptureFFUScriptPath = "$FFUDevelopmentPath\WinPECaptureFFUFiles\CaptureFFU.ps1" + # Workaround for PowerShell 7 issue on Windows 11 23H2 and earlier + # https://github.com/PowerShell/PowerShell/issues/21645 + $osBuild = (Get-CimInstance -ClassName Win32_OperatingSystem).BuildNumber + if ($osBuild -le 22631) { + WriteLog "Applying workaround for PowerShell 7 LocalAccounts module issue on Windows 11 build $osBuild" + Import-Module Microsoft.PowerShell.LocalAccounts -UseWindowsPowerShell + } + If (-not (Test-Path -Path $FFUCaptureLocation)) { WriteLog "Creating FFU capture location at $FFUCaptureLocation" New-Item -Path $FFUCaptureLocation -ItemType Directory -Force