Fixed bug with Windows Update failing to install updates for VHDX-only captures.

This commit is contained in:
rbalsleyMSFT
2023-12-14 15:32:14 -08:00
parent 4d8966d3a1
commit ed3fcf1a3d
3 changed files with 18 additions and 4 deletions
+16 -3
View File
@@ -207,7 +207,7 @@ param(
[bool]$CopyUnattend,
[bool]$RemoveFFU
)
$version = '2309.2'
$version = '2312.1'
#Check if Hyper-V feature is installed (requires only checks the module)
$osInfo = Get-WmiObject -Class Win32_OperatingSystem
@@ -1067,6 +1067,7 @@ function Remove-FFUVM {
WriteLog "Removing VM: $VMName"
Remove-VM -Name $VMName -Force
WriteLog 'Removal complete'
$VMPath = $FFUVM.Path
WriteLog "Removing $VMPath"
Remove-Item -Path $VMPath -Force -Recurse
WriteLog 'Removal complete'
@@ -1119,6 +1120,9 @@ Function Remove-FFUUserShare {
}
Function Get-WindowsVersionInfo {
#This sleep prevents CBS/CSI corruption which causes issues with Windows update after deployment. Capturing from very fast disks (NVME) can cause the capture to happen faster than Windows is ready for. This seems to affect VHDX-only captures, not VM captures.
WriteLog 'Sleep 60 seconds before opening registry to grab Windows version info '
Start-sleep 60
WriteLog "Getting Windows Version info"
#Load Registry Hive
$Software = "$osPartitionDriveLetter`:\Windows\System32\config\software"
@@ -1157,8 +1161,6 @@ Function Get-WindowsVersionInfo {
WriteLog 'Sleep 60 seconds to allow registry to completely unload'
Start-sleep 60
return @{
DisplayVersion = $DisplayVersion
@@ -1283,6 +1285,17 @@ Function New-DeploymentUSB {
function Get-FFUEnvironment {
WriteLog 'Dirty.txt file detected. Last run did not complete succesfully. Will clean environment'
# Check for running VMs that start with '_FFU-' and are in the 'Off' state
$vms = Get-VM
# Loop through each VM
foreach ($vm in $vms) {
# Check if the VM name starts with '_FFU-' and the state is 'Off'
if ($vm.Name.StartsWith("_FFU-") -and $vm.State -eq 'Off') {
# If conditions are met, delete the VM
Remove-FFUVM -VMName $vm.Name
}
}
# Check for MSFT Virtual disks where location contains FFUDevelopment in the path
$disks = Get-Disk -FriendlyName *virtual*
foreach ($disk in $disks) {
@@ -60,6 +60,7 @@ Remove-Variable DisplayVersion
Remove-Variable Office
reg unload "HKLM\FFU"
#This prevents Critical Process Died errors you can have during deployment of the FFU - may not happen during capture from WinPE, but adding here to be consistent with VHDX capture
Write-Host "Sleeping for 60 seconds to allow registry to unload prior to capture"
Start-sleep 60
Start-Process -FilePath dism.exe -ArgumentList $dismArgs -Wait -PassThru -ErrorAction Stop | Out-Null
#Copy DISM log to Host
@@ -117,7 +117,7 @@ $LogFileName = 'ScriptLog.txt'
$USBDrive = Get-USBDrive
New-item -Path $USBDrive -Name $LogFileName -ItemType "file" -Force | Out-Null
$LogFile = $USBDrive + $LogFilename
$version = '2309.2'
$version = '2312.1'
WriteLog 'Begin Logging'
WriteLog "Script version: $version"