Windows PE (WinPE) is a small operating system used to install, deploy, and repair Windows desktop editions, Windows Server, and other Windows operating systems. From Windows PE, you can:

  • Set up your hard drive before installing Windows.
  • Install Windows by using apps or scripts from a network or a local drive.
  • Capture and apply Windows images.
  • Modify the Windows operating system while it's not running.
  • Set up automatic recovery tools.
  • Recover data from unbootable devices.
  • Add your own custom shell or GUI to automate these kinds of tasks.


Setup Environemnt
===============================
powershell
$ADKWPEPath = "C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64"
$winPE = "C:\WinPe_amd64"
$winPEISO = "$winPE\ISO"
$winPEMount = "$winPE\mount"
$PackagePath = "$ADKWPEPath\WinPE_OCs"
$lang="en-us"


Mount Base WinPE image
===============================
New-Item -Type Directory $winPEMount
Dism /Mount-Image /ImageFile:"$ADKWPEPath\$lang\winpe.wim" /index:1 /MountDir:$winPEMount


Add Third-Party driver
===============================
Dism /image:$winPEMount /Add-Driver /Driver:C:\Temp\Drivers\Windows10-x64\LewisburgSystem.inf

Check:
Dism /Image:$winPEMount /Get-Drivers

 

Add Windows Powershell and apps
===============================
Dism /Add-Package /Image:"C:\WinPE_amd64\mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-WMI.cab"
Dism /Add-Package /Image:"C:\WinPE_amd64\mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\en-us\WinPE-WMI_en-us.cab"
Dism /Add-Package /Image:"C:\WinPE_amd64\mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-NetFX.cab"
Dism /Add-Package /Image:"C:\WinPE_amd64\mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\en-us\WinPE-NetFX_en-us.cab"
Dism /Add-Package /Image:"C:\WinPE_amd64\mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-Scripting.cab"
Dism /Add-Package /Image:"C:\WinPE_amd64\mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\en-us\WinPE-Scripting_en-us.cab"
Dism /Add-Package /Image:"C:\WinPE_amd64\mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-PowerShell.cab"
Dism /Add-Package /Image:"C:\WinPE_amd64\mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\en-us\WinPE-PowerShell_en-us.cab"
Dism /Add-Package /Image:"C:\WinPE_amd64\mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-StorageWMI.cab"
Dism /Add-Package /Image:"C:\WinPE_amd64\mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\en-us\WinPE-StorageWMI_en-us.cab"
Dism /Add-Package /Image:"C:\WinPE_amd64\mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-DismCmdlets.cab"
Dism /Add-Package /Image:"C:\WinPE_amd64\mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\en-us\WinPE-DismCmdlets_en-us.cab"

$cmdPath = "$winPEMount\Windows\System32\startnet.cmd"
$sshPath = "X:\Apps\OpenSSH-Win64\"
$zipPath = "X:\Apps\7-Zip\"
$expPath = "X:\Apps\explorerpp\"
$notPath = "X:\Apps\Notepadpp\"
Add-Content -Path $cmdPath -Value "set PATH=%PATH%;$sshPath;$zipPath;$expPath;$notPath"

$cmdPath = "$winPEMount\Windows\System32\startnet.cmd"
Add-Content -Path $cmdPath -Value "cls"
Add-Content -Path $cmdPath -Value "PowerShell"
Add-Content -Path $cmdPath -Value "Explorer++.exe"


Commit the changes
===============================
Dism /Unmount-Image /MountDir:$winPEMount /commit
copype amd64 $winPEISO
MakeWinPEMedia /ISO $winPEISO $winPEISO\WinPE_amd64.iso


Clean up - when not possible to mount/unmount
===============================
dism /cleanup-wim


Create WinPE ISO
===============================
copype amd64 $winPEISO
MakeWinPEMedia /ISO $winPEISO $winPEISO\WinPE_amd64.iso