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
This commit is contained in:
rbalsleyMSFT
2025-08-06 15:56:21 -07:00
parent a87c4796b5
commit 59e247c012
+8
View File
@@ -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