Skip to content

Update Update-BootWIM.ps1 #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 30 additions & 21 deletions Update-BootWIM.ps1
Original file line number Diff line number Diff line change
@@ -1,33 +1,42 @@
<#
Stripped down script from https://learn.microsoft.com/en-us/windows/deployment/update/media-dynamic-update
<#
Stripped down version of 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
Version 0.2 - 2023-05-14
Sassan Fanai

#>

#Requires -RunAsAdministrator

param (
$UpdateFile = "C:\mediaRefresh\packages\LCU.msu",
$WimFile = "C:\Boot Image Backup\boot.wim",
$StagingPath = "C:\mediaRefresh\Temp"
)

function Get-TS { return "{0:HH:mm:ss}" -f [DateTime]::Now }

Write-Output "$(Get-TS): Starting media refresh"
if (!(Test-Path $UpdateFile)) {
Write-Output "$(Get-TS): No update file found @ [$UpdateFile]. Exiting..."
break
}

if (!(Test-Path $WimFile)) {
Write-Output "$(Get-TS): No WIM file found @ [$WimFile]. Exiting..."
break
}

Write-Output "$(Get-TS): Starting media refresh of [$WimFile]"

# Declare Dynamic Update packages
$LCU_PATH = "C:\mediaRefresh\packages\LCU.msu"
$BOOT_WIM = "C:\Boot Image Backup\boot.wim"
$LCU_PATH = $UpdateFile
$BOOT_WIM = $WimFile

# Declare folders for mounted images and temp files
$WORKING_PATH = "C:\mediaRefresh\temp"
$WINPE_MOUNT = "C:\mediaRefresh\temp\WinPEMount"
$WORKING_PATH = "$StagingPath"
$WINPE_MOUNT = "$StagingPath\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)) {
Expand All @@ -47,12 +56,12 @@ $WINPE_IMAGES = Get-WindowsImage -ImagePath $BOOT_WIM
Foreach ($IMAGE in $WINPE_IMAGES) {

# update WinPE
Write-Output "$(Get-TS): Mounting WinPE, image index $($IMAGE.ImageIndex)"
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"
Write-Output "$(Get-TS): Adding package [$LCU_PATH]"
Add-WindowsPackage -Path $WINPE_MOUNT -PackagePath $LCU_PATH | Out-Null
}
Catch
Expand All @@ -76,9 +85,9 @@ Foreach ($IMAGE in $WINPE_IMAGES) {
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

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
Write-Output "$(Get-TS): Moving updated and exported boot2.wim from staging area [$StagingPath] to [$BOOT_WIM]"
Move-Item -Path $WORKING_PATH"\boot2.wim" -Destination $BOOT_WIM -Force -ErrorAction stop | Out-Null