-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathUpdate-BootWIM.ps1
More file actions
84 lines (64 loc) · 2.84 KB
/
Update-BootWIM.ps1
File metadata and controls
84 lines (64 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<#
Stripped down script from https://learn.microsoft.com/en-us/windows/deployment/update/media-dynamic-update
to update WinPE/boot image/boot.wim.
You need to download the approproiate CU for the boot image version you are using.
Copy the CU to $LCU_PATH. Copy your boot.wim file to $BOOT_WIM.
Version 0.1 - 2023-05-10
Sassan Fanai
#>
#Requires -RunAsAdministrator
function Get-TS { return "{0:HH:mm:ss}" -f [DateTime]::Now }
Write-Output "$(Get-TS): Starting media refresh"
# Declare Dynamic Update packages
$LCU_PATH = "C:\mediaRefresh\packages\LCU.msu"
$BOOT_WIM = "C:\Boot Image Backup\boot.wim"
# Declare folders for mounted images and temp files
$WORKING_PATH = "C:\mediaRefresh\temp"
$WINPE_MOUNT = "C:\mediaRefresh\temp\WinPEMount"
# Check for LCU MSU
if (!(Test-Path $LCU_PATH)) {
Write-Output "$(Get-TS): No LCU.msu found. You nned to download and copy the CU for your boot image version to $LCU_PATH and rename the file to LCU.msu"
break
}
# Create folders for mounting images and storing temporary files
if (!(Test-Path $WORKING_PATH)) {
New-Item -ItemType directory -Path $WORKING_PATH -ErrorAction Stop | Out-Null
}
if (!(Test-Path $WINPE_MOUNT)) {
New-Item -ItemType directory -Path $WINPE_MOUNT -ErrorAction stop | Out-Null
}
#
# update Windows Preinstallation Environment (WinPE)
#
# Get the list of images contained within WinPE
$WINPE_IMAGES = Get-WindowsImage -ImagePath $BOOT_WIM
Foreach ($IMAGE in $WINPE_IMAGES) {
# update WinPE
Write-Output "$(Get-TS): Mounting WinPE, image index $($IMAGE.ImageIndex)"
Mount-WindowsImage -ImagePath $BOOT_WIM -Index $IMAGE.ImageIndex -Path $WINPE_MOUNT -ErrorAction stop | Out-Null
try
{
Write-Output "$(Get-TS): Adding package $LCU_PATH"
Add-WindowsPackage -Path $WINPE_MOUNT -PackagePath $LCU_PATH | Out-Null
}
Catch
{
$theError = $_
Write-Output "$(Get-TS): $theError"
if ($theError.Exception -like "*0x8007007e*") {
Write-Output "$(Get-TS): This failure is a known issue with combined cumulative update, we can ignore."
}
else {
throw
}
}
# Perform image cleanup
Write-Output "$(Get-TS): Performing image cleanup on WinPE"
DISM /image:$WINPE_MOUNT /cleanup-image /StartComponentCleanup | Out-Null
# Dismount
Dismount-WindowsImage -Path $WINPE_MOUNT -Save -ErrorAction stop | Out-Null
#Export WinPE
Write-Output "$(Get-TS): Exporting image to $WORKING_PATH\boot2.wim"
Export-WindowsImage -SourceImagePath $BOOT_WIM -SourceIndex $IMAGE.ImageIndex -DestinationImagePath $WORKING_PATH"\boot2.wim" -ErrorAction stop | Out-Null
}
Move-Item -Path $WORKING_PATH"\boot2.wim" -Destination $BOOT_WIM -Force -ErrorAction stop | Out-Null