Windows Imaging
Prerequisites
- Windows ADK with Deployment Tools, Configuration Designer, and the Windows PE add-on installed
- Download the ADK for the version of Windows that you will be working on.
- Download and install the Windows ADK | Microsoft Learn
- A Virtualized Environment
- Hyper-V Manager and Hyper-V installed
- Oracle's VirtualBox if approved.
- Windows Server or Desktop OS ISO file.
Getting Started
- Create a virtual machine with minimal resources, we only need it for installing OS staging to capture the .WIM image.
- 4-6GB of RAM
- 2 vCPU
- Install the base Windows image to the VM.
- Once you get to the OOBE screen to finish the Windows Install, enter audit mode by pressing CTRL+SHIFT+F3.
- Windows will log you in and bring up a SysPrep Menu, press cancel on that menu.
- Start image customization.
Removing Pre-Installed Provisioned Apps
From and administrator PowerShell prompt type: Get-AppxProvisionedPackage -online
- Your output should look like below
DisplayName : Microsoft.BingWeather
Version : 4.25.20211.0
Architecture : neutral
ResourceId : ~
PackageName : Microsoft.BingWeather_4.25.20211.0_neutral_~_8wekyb3d8bbwe
Regions :
You can remove some of these apps by typing: Remove-AppxProvisionedPackage -Online -PackageName Microsoft.BingWeather_4.25.20211.0_neutral_~_8wekyb3d8bbwe
If you have already compiled your .WIM image, you can mount it to a temporary directory and remove the apps like below.
The below 29 apps can be removed with very minimal effect on Windows
Remove-AppxProvisionedPackage -Path D:\tempmount -PackageName Microsoft.549981C3F5F10_1.1911.21713.0_neutral_~_8wekyb3d8bbwe
Remove-AppxProvisionedPackage -Path D:\tempmount -PackageName Microsoft.BingWeather_4.25.20211.0_neutral_~_8wekyb3d8bbwe
Remove-AppxProvisionedPackage -Path D:\tempmount -PackageName Microsoft.GetHelp_10.1706.13331.0_neutral_~_8wekyb3d8bbwe
Remove-AppxProvisionedPackage -Path D:\tempmount -PackageName Microsoft.Getstarted_8.2.22942.0_neutral_~_8wekyb3d8bbwe
Remove-AppxProvisionedPackage -Path D:\tempmount -PackageName Microsoft.Microsoft3DViewer_6.1908.2042.0_neutral_~_8wekyb3d8bbwe
Remove-AppxProvisionedPackage -Path D:\tempmount -PackageName Microsoft.MicrosoftOfficeHub_18.1903.1152.0_neutral_~_8wekyb3d8bbwe
Remove-AppxProvisionedPackage -Path D:\tempmount -PackageName Microsoft.MicrosoftSolitaireCollection_4.4.8204.0_neutral_~_8wekyb3d8bbwe
Remove-AppxProvisionedPackage -Path D:\tempmount -PackageName Microsoft.MixedReality.Portal_2000.19081.1301.0_neutral_~_8wekyb3d8bbwe
Remove-AppxProvisionedPackage -Path D:\tempmount -PackageName Microsoft.Office.OneNote_16001.12026.20112.0_neutral_~_8wekyb3d8bbwe
Remove-AppxProvisionedPackage -Path D:\tempmount -PackageName Microsoft.People_2019.305.632.0_neutral_~_8wekyb3d8bbwe
Remove-AppxProvisionedPackage -Path D:\tempmount -PackageName Microsoft.SkypeApp_14.53.77.0_neutral_~_kzf8qxf38zg5c
Remove-AppxProvisionedPackage -Path D:\tempmount -PackageName Microsoft.Wallet_2.4.18324.0_neutral_~_8wekyb3d8bbwe
Remove-AppxProvisionedPackage -Path D:\tempmount -PackageName Microsoft.WindowsFeedbackHub_2019.1111.2029.0_neutral_~_8wekyb3d8bbwe
Remove-AppxProvisionedPackage -Path D:\tempmount -PackageName Microsoft.WindowsMaps_2019.716.2316.0_neutral_~_8wekyb3d8bbwe
Remove-AppxProvisionedPackage -Path D:\tempmount -PackageName Microsoft.Xbox.TCUI_1.23.28002.0_neutral_~_8wekyb3d8bbwe
Remove-AppxProvisionedPackage -Path D:\tempmount -PackageName Microsoft.XboxApp_48.49.31001.0_neutral_~_8wekyb3d8bbwe
Remove-AppxProvisionedPackage -Path D:\tempmount -PackageName Microsoft.XboxGameOverlay_1.46.11001.0_neutral_~_8wekyb3d8bbwe
Remove-AppxProvisionedPackage -Path D:\tempmount -PackageName Microsoft.XboxGamingOverlay_2.34.28001.0_neutral_~_8wekyb3d8bbwe
Remove-AppxProvisionedPackage -Path D:\tempmount -PackageName Microsoft.XboxIdentityProvider_12.50.6001.0_neutral_~_8wekyb3d8bbwe
Remove-AppxProvisionedPackage -Path D:\tempmount -PackageName Microsoft.XboxSpeechToTextOverlay_1.17.29001.0_neutral_~_8wekyb3d8bbwe
Remove-AppxProvisionedPackage -Path D:\tempmount -PackageName Microsoft.YourPhone_2019.430.2026.0_neutral_~_8wekyb3d8bbwe
Remove-AppxProvisionedPackage -Path D:\tempmount -PackageName Microsoft.ZuneMusic_2019.19071.19011.0_neutral_~_8wekyb3d8bbwe
Remove-AppxProvisionedPackage -Path D:\tempmount -PackageName Microsoft.ZuneVideo_2019.19071.19011.0_neutral_~_8wekyb3d8bbwe
Remove-AppxProvisionedPackage -Path D:\tempmount -PackageName Microsoft.ScreenSketch_2019.904.1644.0_neutral_~_8wekyb3d8bbwe
Remove-AppxProvisionedPackage -Path D:\tempmount -PackageName Microsoft.WindowsAlarms_2019.807.41.0_neutral_~_8wekyb3d8bbwe
Remove-AppxProvisionedPackage -Path D:\tempmount -PackageName Microsoft.windowscommunicationsapps_16005.11629.20316.0_neutral_~_8wekyb3d8bbwe
Remove-AppxProvisionedPackage -Path D:\tempmount -PackageName Microsoft.WindowsSoundRecorder_2019.716.2313.0_neutral_~_8wekyb3d8bbwe
Remove-AppxProvisionedPackage -Path D:\tempmount -PackageName Microsoft.WindowsStore_11910.1002.513.0_neutral_~_8wekyb3d8bbwe
Remove-AppxProvisionedPackage -Path D:\tempmount -PackageName Microsoft.MSPaint_2019.729.2301.0_neutral_~_8wekyb3d8bbwe
Mounting and Unmounting an already captured .WIM file
- Run the below commands to mount the WIM image to a temporary directory.
- Make sure the temporary directory has enough space as the .WIM file will be unpacked to that
REM Mount the image
Dism /Mount-Image /ImageFile:"D:\BaseCVX.wim" /Index:1 /MountDir:"D:\tempmount"
REM Unmount the image
Dism /Unmount-Image /MountDir:"D:\tempmount" /Commit
REM might have to run this if having trouble unmounting
DISM /cleanup-wim
Installing Drivers in the Base Image
- From audit mode you can install drivers to the base image directly.
- The general guidance is to only install the required drivers for storage, networking and sometimes video.
- You can create a "Thick" image by installing all the drivers ahead of time. This can simplify deployment if needed. This should be limited to 2-3 models of the same brand as doing too many can cause issues and increase the size of the image
- The below PowerShell command will install all .inf drivers from a folder. (Install Windows Drivers from a Folder Using PowerShell - chrisbrown.au)
Get-ChildItem "C:\mydrivers\" -Recurse -Filter "*.inf" |
ForEach-Object { PNPUtil.exe /add-driver $_.FullName /install }
Installing Windows Updates in the Base Image
- Updates can be installed automatically or manually by downloading the necessary KBs from the Microsoft Update Catalog and then transferring them to the VM.
- Once transferred, just install and reboot the machine to finalize the update.
Capturing the Base image
- Sysprep the image
- C:\Windows\System32\Sysprep\Sysprep.exe /generalize /oobe /shutdown
- Boot from WinPE flash drive and run the below to capture the image
- Dism /Capture-Image /ImageFile:"H:\BaseImage.wim" /CaptureDir:C:\ /Name:"Base Image"
Deploying the image
- Boot from WinPE flash drive
- Verify the disk that we will be installing Windows to is Disk 0, if you are installing it to another disk make sure to change the CreatePartitions script before running it.
- After running the partitions script, run the ApplyImage.bat with the image as a parameter i.e ApplyImage.bat BaseImage.wim