private/Step-BuildBootAddWinpeJpg.ps1
|
#Requires -PSEdition Core function Step-BuildBootAddWinpeJpg { <# .SYNOPSIS Adds the embedded wallpaper and registry setting to a mounted WinRE image .DESCRIPTION For a WinRE source, decodes the embedded JPEG to TEMP, copies it to Windows\System32\winpe.jpg in the mounted image, and creates a temporary INF that registers the image as the custom WinPE background. Add-WindowsDriver applies the unsigned INF to the mounted image. The function performs no changes when global BuildMedia.WimSourceType is not WinRE. robocopy.exe and Add-WindowsDriver output is suppressed. .EXAMPLE PS> Step-BuildBootAddWinpeJpg Adds the embedded wallpaper when the current build source is WinRE. .INPUTS None. This function does not accept pipeline input. .OUTPUTS None. .NOTES Author: David Segura Company: Recast Software Version: 0.1.0 Date: 2026-08-28 Requires global BuildMedia with MountPath, LogsPath, and WimSourceType properties, robocopy.exe, and Add-WindowsDriver. Creates winpe.jpg and an INF in TEMP and modifies the mounted WinRE image. #> [CmdletBinding()] param () $MountPath = $global:BuildMedia.MountPath $LogsPath = $global:BuildMedia.LogsPath $WimSourceType = $global:BuildMedia.WimSourceType if ($WimSourceType -ne 'WinRE') { Write-Verbose "[$($MyInvocation.MyCommand.Name)] Wallpaper injection skipped for non-WinRE source" return } $InfWinpeJpg = @' [Version] Signature = "$WINDOWS NT$" Class = System ClassGuid = {4D36E97d-E325-11CE-BFC1-08002BE10318} Provider = OSDeploy DriverVer = 07/20/2021,2021.07.20.0 [DefaultInstall] AddReg = AddReg [AddReg] ;rootkey,[subkey],[value],[flags],[data] ;0x00000 REG_SZ ;0x00001 REG_BINARY ;0x10000 REG_MULTI_SZ ;0x20000 REG_EXPAND_SZ ;0x10001 REG_DWORD ;0x20001 REG_NONE HKLM,"SOFTWARE\Microsoft\Windows NT\CurrentVersion\WinPE",CustomBackground,0x10000,"X:\Windows\System32\winpe.jpg" '@ # Small dark placeholder wallpaper (base64-encoded JPEG) $Wallpaper = '/9j/4AAQSkZJRgABAgEAYABgAAD//gASTEVBRFRPT0xTIHYyMy4wAP/bAIQABQUFCAUIDAcHDAwJCQkMDQwMDAwNDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQEFCAgKBwoMBwcMDQwKDA0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0N/8QBogAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoLAQADAQEBAQEBAQEBAAAAAAAAAQIDBAUGBwgJCgsQAAIBAwMCBAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBkaJSYnKCkqNDU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2drh4uPk5ebn6Onq8fLz9PX29/j5+hEAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/8AAEQgAIAAgAwERAAIRAQMRAf/aAAwDAQACEQMRAD8A42v6PPxQKACgAoAKACgAoAKACgAoAKACgAoAKACgAoA//9k=' Write-Host -ForegroundColor DarkGray "[$(Get-Date -format s)] [INFO] Updating WinRE Wallpaper $MountPath\Windows\System32\winpe.jpg" [byte[]]$Bytes = [Convert]::FromBase64String($Wallpaper) [System.IO.File]::WriteAllBytes("$env:TEMP\winpe.jpg", $Bytes) $null = robocopy.exe "$env:TEMP" "$MountPath\Windows\System32" winpe.jpg /b /ndl /np /r:0 /w:0 /xj /mt:128 /LOG+:"$LogsPath\Step-BuildBootAddWinpeJpg.log" # Inject the WinRE Wallpaper Driver INF $InfFile = "$env:TEMP\Set-WinREWallpaper.inf" $null = New-Item -Path $InfFile -Force Set-Content -Path $InfFile -Value $InfWinpeJpg -Encoding Unicode -Force $null = Add-WindowsDriver -Path $MountPath -Driver $InfFile -ForceUnsigned } |