Prepare Windows installation media

Prepare Windows installation media using the recorded offline-image workflow: select source files, partition the USB drive, service the image and split the resulting WIM. The prerequisites and drive-letter examples are listed below.

Prepare Windows installation media

Slipstreaming is the process where a Windows installation image (.WIM) has various components added to it in such a way that a fresh installation of Windows has those components in place from the start.

The source uses this to pre-apply:

  • Windows Cumulative Updates (CUs) and other updates
  • Device drivers, especially storage drivers for the Setup environment
  • Settings via Registry keys, e.g. pre-configuring keys for Delivery Optimisation to apply before the device is Intune registered

Because the drivers are added to the Windows DriverStore, adding drivers for multiple hardware SKUs can take up significant additional space. As a result it's generally good practice to keep installation media configured only for similar devices from one manufacturer.

It's also worth excluding display drivers from the image, as these are both very large (AMD typically ~1GB, Intel often 1.5GB), frequently updated, and always available from Windows Update.

Pre-requisites

  • Windows 11 25H2 Education ISO (or later)
  • Ideally this will be the version most recently updated by Microsoft, although you will also see listed the original release ISO
  • A folder structure as below:
  • C:\Image
  • Mount
  • Wim
  • ISO
  • Drivers
  • Storage
  • Other
  • Updates
  • The device you will be building the image files on should be added to the group CCM: Modified Scan Locations which will apply a Defender exception to avoid on-demand scanning of the folders above
  • USB removable drives
  • 16GB minimum, larger is better
  • 64GB drives are typically very good value for money
  • Speed is important; a difference of a few $ in purchase price can represent 2-3 minutes of additional time taken per device OS installation
  • It's recommended you have some keytags or labels you can apply to the drives

Preparing the source files

ISO and WIM files

  1. Place the ISO in C:\image\iso
  2. Remove the Mark Of The Web Unblock-File C:\image\iso\Windows_11_25H2.ISO
  3. Mount the ISO in Explorer and note the drive letter - usually D:
  4. Identify the Education index (this should be Index 1 if you have downloaded the Education ISO) Get-WindowsImage -ImagePath d:\sources\install.wim
  5. Export the image with: Export-WindowsImage -SourceImagePath d:\sources\install.wim -SourceIndex 1 -DestinationImagePath C:\image\wim\\25h2_edu_<model>.wim
  6. e.g.: Export-WindowsImage -SourceImagePath d:\sources\install.wim -SourceIndex 1 -DestinationImagePath C:\image\wim\BM1403\25h2_edu_bm1403.wim

Drivers

  1. Capture third-party drivers from an exemplar device
  2. Storage drivers only (for boot.wim or WinPEDriver) Get-WindowsDriver -Online | Where-Object { $.Inbox -eq $false -and $.BootCritical -eq $true -and $.ClassName -eq "SCSIAdapter" } | ForEach-Object { New-Item -ItemType Directory -Path C:\image\drivers\storage$($.Driver) ; pnputil.exe /export-driver (.Driver) C:\image\drivers\storage$($.Driver) }
  3. All other third-party drivers Get-WindowsDriver -Online | Where-Object { $.Inbox -eq $false -and $.BootCritical -eq $false } | ForEach-Object { New-Item -ItemType Directory -Path C:\image\drivers\other$($.Driver) ; pnputil.exe /export-driver (.Driver) C:\image\drivers\other$($_.Driver) }

Note: pnputil.exe cannot export to a non-existent directory. You must have created the folder structure in advance of this stage.

Once drivers have been captured, move them to a device model subfolder (e.g. C:\image\drivers\BM1403) to avoid mixing drivers from different models.

Cumulative updates

Optional

  1. Download the latest 25H2 Cumulative Update file from https://catalog.update.microsoft.com/ and move the update to C:\image\updates
  • Check a fully updated 25H2 machine for the KB number of search the update catalog, whichever you find easier

Preparing the USB drive to be used as installation media

The source uses manual partitioning rather than Rufus to allow multiple partitions.

Configuring and formatting partitions

Insert the drive and open an Administrative terminal window.

Run:

Diskpart

List disk

Note the disk number of the removable disk, usually 1

Sel disk 1

Clean

This will immediately destroy the partition table; this is obviously destructive, be careful

Create part pri size=32768

The captured 64GB disk example (57GiB usable) has a 32GiB partition for the Windows installation and the rest for other data (scripts, tools, etc.)

Adjust sizes here as desired, or do not specify a size if you want only one partition

Format fs=fat32 quick label=25H2edu

This partition should be automatically re-assigned the drive letter the drive had previously

Create part pri

This fills the rest of the drive with a new partition

Format fs=ntfs quick label=data

NTFS allows us to keep larger files if desired

Assign letter=F

Assuming D is the ISO, E the partition created earlier – adjust as necessary

Exit

Preparing the fat32 partition with boot code

Assuming D: as mounted ISO and E: as fat32 partition:

D:\boot\bootsect.exe /nt60 E:

Copying the source files (minus install.wim)

Use Robocopy to quickly copy all the source files for the windows installation, minus the install.wim to be replaced with the 25h2_edu_<model>.wim

The examples assume D: is the installation drive, E: is the data drive and F: is the mounted ISO:

robocopy F:\ D:\ /e /nfl /r:1 /w:1 /xf install.wim

Mount the Windows image

Mount the Windows image (the 25h2_edu_<model>.wim exported in Preparing the source files

Mount-WindowsImage -ImagePath C:\image\wim\\25h2_edu_<model>.wim -Index 1 -Path C:\image\mount

Delivery Optimisation registry keys

The commands below will pre-configure the Delivery Optimisation settings for a device so as much content as possible can be delivered from your Cache server. This step is optional but beneficial especially at scale.

reg load HKLM\WIM C:\image\mount\Windows\System32\config\SOFTWARE

New-Item -Path "HKLM:\WIM\Policies\Microsoft\Windows\DeliveryOptimization" -Force | Out-Null
New-ItemProperty -Path "HKLM:\WIM\Policies\Microsoft\Windows\DeliveryOptimization" -Name "DOCacheHost" -Value "docache.ccmschools.edu.au" -PropertyType String -Force
New-ItemProperty -Path "HKLM:\WIM\Policies\Microsoft\Windows\DeliveryOptimization" -Name "DOCacheHostSource" -Value 1 -PropertyType DWord -Force

[gc]::Collect()

reg unload HKLM\WIM

Windows CUs

Because these are cumulative updates you will typically delete the previous update when downloading a new one. Occasionally you may need a second update, not a CU but a servicing or non-security update. In this case the source installs the available updates, moving from lower to higher KB numbers. This complex one-liner will find all the MSU files and process them in KB number order.

Get-ChildItem -Path C:\image\updates\ -Filter *.msu | Sort-Object -Property Name | ForEach-Object { try { Write-Host -ForegroundColor Yellow "Adding update (.Name.Split('-')[1])" ; Add-WindowsPackage -PackagePath (.FullName) -Path C:\image\mount\ ; Write-Host -ForegroundColor Green "Installed successfully" } catch { Write-Host -ForegroundColor Red "Error encountered, dismount Windows image and discard changes" }

It is possible to try to reduce the size of the windows image after slipstreaming but this is rarely sufficiently beneficial to bother with.

After slipstreaming CUs

When the CUs have been added it is good practice to save the changes made, and then create a copy of the WIM to mount and add drivers to. This allows you to quickly generate several WIMs with different driver sets for different hardware without needing to re-slipstream a CU.

Dismount-WindowsImage -Path C:\image\mount\ -Save

Copying the WIM and remounting it is a simple modification of existing commands.

Drivers

This stage assumes drivers were already exported from an exemplar device into a model-specific subfolder. The next commands add those drivers to the Windows image.

Storage drivers

These can be copied from the storage folder to a folder on either of your installation drive partitions called WinPEDriver

Device drivers

Usually it is sufficient to run:

Add-WindowsDriver -Recurse -Driver C:\image\drivers\ -Path C:\image\mount\ -ErrorAction SilentlyContinue

In rare instances the Add-WindowsDriver cmdlet can fail where the dism.exe command can succeed. In this case, try:

dism.exe /Image:C:\image\mount /Add-Driver /Driver:C:\image\drivers\bootcritical /Recurse /ForceUnsigned

Dismount and save the Windows Image

To save changes, dismount the image with -Save; to start over without the changes, use -Discard.

Dismount-WindowsImage -Path C:\image\mount -Save

Split the Windows Image

Split the image into smaller pieces to fit it on the FAT32 partition.

Split-WindowsImage -ImagePath C:\image\wim\\25h2_edu_<model>.wim -SplitImagePath C:\image\wim\\install.swm -FileSize 3072

Copy split image files to the disk

Copy your install.swm, install1.swm etc. files to D:\Sources

Unattended files

If the boot.wim file contains storage drivers for your device already, you can use an unattended file to auto-wipe, partition, and format the device hard drive before installing Windows.

For devices where the driver is loaded from WinPEDriver the drive number assignment will change and may not be 100% predictable, so any existing autounattend.xml files will need adjustment.