Skip to content

Instantly share code, notes, and snippets.

@QNimbus
Last active January 8, 2025 01:01
Show Gist options
  • Save QNimbus/5fb63dff6159b5a794b30629959d888e to your computer and use it in GitHub Desktop.
Save QNimbus/5fb63dff6159b5a794b30629959d888e to your computer and use it in GitHub Desktop.
Customize Windows RE

Customize Windows RE

For the current session

Set-ExecutionPolicy "Unrestricted"

Download Windows 11 ISO

Create temporary folders

New-Item -Path "c:\mount\windows" -ItemType "directory" -Force New-Item -Path "c:\mount\winre" -ItemType "directory" -Force

Copy ISO to folder

Copy-Item "$Env:USERPROFILE\Downloads\Win11_22H2_English_x64v1.iso" -Destination "C:\mount"

Extract install.wim from ISO

Copy-Item "D:\sources\install.wim" -Destination "C:\mount"

Unpack all Intel Rapid Storage drivers in C:\mount\drivers

Get-ChildItem -Recurse -Path "C:\mount\drivers\15063\Drivers" -Filter *.inf | ForEach-Object {
    Dism /Image:C:\mount\winre /Add-Driver /Driver:"$_"
}

Optimizing the image

Dism /Image:c:\mount\winre /Cleanup-Image /StartComponentCleanup

Unmount the WinRE image

Dism /Unmount-Image /MountDir:C:\mount\winre /Commit

Optimizing the image, part 2

Export the Windows RE image into a new Windows image file.

Dism /Export-Image /SourceImageFile:c:\mount\windows\windows\system32\recovery\winre.wim /SourceIndex:1 /DestinationImageFile:c:\mount\winre-optimized.wim

Replace the old Windows RE image with the newly-optimized image.

Remove-Item c:\mount\windows\windows\system32\recovery\winre.wim
Copy-Item "c:\mount\winre-optimized.wim" -Destination "c:\mount\windows\windows\system32\recovery\winre.wim"
Copy-Item "c:\mount\windows\Windows\System32\Recovery\winre.wim" -Destination "c:\Windows\system32\Recovery\"	

Unmount the Windows image

Dism /Unmount-Image /MountDir:C:\mount\windows /Commit

Mount recovery partition using DISKPART

DISKPART> list disk

  Disk ###  Status         Size     Free     Dyn  Gpt
  --------  -------------  -------  -------  ---  ---
  Disk 0    Online          953 GB  1024 KB        *

DISKPART> select disk 0

Disk 0 is now the selected disk.

DISKPART> list partition

  Partition ###  Type              Size     Offset
  -------------  ----------------  -------  -------
  Partition 1    System             100 MB  1024 KB
  Partition 2    Reserved            16 MB   101 MB
  Partition 3    Primary            953 GB   117 MB
  Partition 4    Recovery           625 MB   953 GB

DISKPART> select partition=4

Partition 4 is now the selected partition.

DISKPART> assign letter=R

DiskPart successfully assigned the drive letter or mount point.

DISKPART> exit

Leaving DiskPart...

Create a new directory in the Wndows RE Tools partitions

New-Item -Path "r:\Recovery\WindowsRE" -ItemType "directory" -Force

Copy-Item "c:\mount\windows\windows\system32\recovery\winre.wim" -Destination "r:\Recovery\WindowsRE"

Register your custom Windows RE tools image

c:\Windows\System32\Reagentc /setreimage /path r:\Recovery\WindowsRE /target c:\Windows

c:\Windows\System32\Reagentc /info

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment