You dont have javascript enabled! Please enable it!

How To Create a Custom WinPE Boot Image With PowerShell Support #PowerShell #Deploy #WindowsServer

5 Min. Read


Microsoft Windows Preinstallation Environment (WinPE) is a lightweight version of Windows used for the deployment of PCs, workstations, and servers, or troubleshooting an operating system while it is offline. WinPE is a stripped down version of Windows that can be booted via PXE, USB, DVD, or virtual media drive such as iLO (HPE), iDRAC (DELL EMC), or Cisco UCS Manager to provide a quick way to deploy an Operating System onto targeted machine.

Out of the box, WinPE contains basic elements. To make it really useful, it generally has to be modified. For example, it comes with a minimum number of device drivers. Therefore, it is often necessary to add additional device drivers that you know will be needed to deploy your system. For example, if you are using HPE servers, you can also inject specific hardware drivers. WinPE also comes with basic command-line scripting abilities.

The purpose of this article is to show you how to customize a WinPE boot image that has PowerShell enabled for advanced scripting capabilities.

Assessment and Deployment Kit (ADK)

The copy of WinPE is available as part of Microsoft’s Assessment and Deployment Kit (ADK). It is best to always use the latest kit. Newer kits work with earlier versions of the operating system. As of this writing, the latest kit available for Windows 10, is version 1709. You can download Windows ADK for Windows 10, version 1709 from the following link:

How To Create a Custom WinPE Boot Image With PowerShell Support #PowerShell #Deploy #WindowsServer 2

When you launch the installation of ADK from the above link, you will be presented with two options – one to install ADK as online installation and the second one is to download all the files needed for offline installation. You can choose the desired option.

The ADK contains more capabilities than what we need here. When you run the installation, you will be presented with a window similar to the following screenshot, all what you need for this process are the Deployment Tools and Windows Preinstallation Environment (Windows PE). Unselect all other options and click Install.

How To Create a Custom WinPE Boot Image With PowerShell Support #PowerShell #Deploy #WindowsServer 3

Setting up the WinPE environment

The Windows Assessment and Deployment Kit (Windows ADK) includes a batch file that creates an environment for working with WinPE images. This batch file requires two arguments. The first one is the architecture type of the target image, we will use amd64, because we will deploy Windows Server 2016 (That’s the topic of my next post. Stay tuned!). The second argument is, the working folder. In this example, the location for the WinPE folder will be D:\TempPE\

Now take the following steps:

  1. On the workstation where you installed Windows ADK, open Deployment and Imaging Tools Environment cmd.
  2. Type the following command: copype.cmd amd64 D:\TempPE\ How To Create a Custom WinPE Boot Image With PowerShell Support #PowerShell #Deploy #WindowsServer 4
  3. The command above will create the specified directory for you. Ensure there were no
    errors during this operation.
  4. Included in the copied file is a boot.wim file that we will be modifying. The boot.wim image is located at D:\TempPE\media\sources\boot.wim
  5. In order to modify it, we need to mount it to make it available to the system. The following DISM command mounts the boot.wim file. Please make sure that you are running an elevated command prompt to complete these tasks.
    Dism /Mount-Image /ImageFile:D:\TempPE\media\sources\boot.wim /index:1 /MountDir:D:\TempPE\mount

    How To Create a Custom WinPE Boot Image With PowerShell Support #PowerShell #Deploy #WindowsServer 5

  6. The boot.wim image that was just mounted contains default Windows device drivers. It is necessary to inject specific boot-critical drivers for the custom WinPE boot.wim image, please check with your preferred hardware vendor to get those drivers before you continue with the remaining steps. In this example, I will use the latest HPE Windows Driver Pack Version 11.01.
  7. Copy the drivers to a folder located on the same workstation.
  8. When inserting multiple device drivers into the image, you may issue a single command to load all the drivers. The following command will find all .inf files in the specified directory and any subdirectories, and then add them to the image:
    Dism /Add-Driver /Image:D:\TempPE\mount /Driver:D:\TempPE\HPE-Windows-DriverPack-V11.01 /Recurse
  9. To see what device drivers are injected into this image, you can use the following command:
    Dism /Get-Drivers /Image:D:\TempPE\mount

Adding Windows PowerShell

WinPE is designed to be a very compact image because it is often used for PXE booting a system, and for that purpose it is desired to keep the image as small as possible. As a result, it comes with the basic command-line capabilities. But with higher speed networks, and using WinPE to boot from USB or DVD media, you can add PowerShell to the image which gives you the ability to create powerful scripts for WinPE to execute for tailoring images.

The following commands demonstrate how to add PowerShell capability into the WinPE image that is required for this example.

  1. First I will store the location of the PowerShell packages to be installed and the location for the temporary Windows PE media in two PowerShell variables named $WinADK and $WinPETemp. Open Windows PowerShell and run the following commands:
    $WinADK='C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs'
  2. The boot.wim image is still mounted from the previous section. You need to make sure the image is mounted before you use the DISM commands and add the PowerShell packages.
  3. At this point, we need to add the PowerShell packages to the WIM file to enhance its capabilities, because it is so much easier to script in PowerShell. The list of all packages (OCS files) can be found under the following location: C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs
  4. To do so, we use the Add-WindowsPackage cmdlet. The following commands demonstrate how to install the six optional PowerShell components to extend WMI capability in a Windows PE environment that are required for this example. You will notice that there are two CAB files per component–the component and its associated language pack. Both are required to be installed. Additionally, the added components often need to be added in a specific sequence.
  5. The following list follows the prescribed sequence. I will use an array of all the CAB file names and then add a loop to make the process easier and more readable.
    $CABfiles = @("$WinADK\","$WinADK\en-us\", "$WinADK\","$WinADK\en-us\", "$WinADK\","$WinADK\en-us\", "$WinADK\","$WinADK\en-us\", "$WinADK\","$WinADK\en-us\", "$WinADK\","$WinADK\en-us\")
    Foreach ($CABfile in $CABfiles) {
            Add-WindowsPackage -PackagePath "$CABFile" -Path "$WinPeTemp\Mount" -IgnoreCheck
  6. In the last step, you need to dismount and save the customization to the image by running the following command:
    Dismount-WindowsImage -path "$WinPETemp\Mount" -save

Creating a WinPE ISO Image

Once the tailoring of WinPE is complete, the files can be saved for use as a bootable image to either an ISO file or a USB drive.

This step is only required if you will be booting WinPE from an ISO image, for example booting from the BMC port such as HPE iLO or integrated DELL EMC Remote Access Controller (iDRAC). You can also create a WinPE bootable USB thumb drive and accomplish the same thing. If you want to know more about this process, please check my recent published Book Getting Started with Nano Server.

  1. First, make sure you are running Windows ADK CMD session with elevated privileges. Open Deployment and Imaging Tools Environment.
  2. You need to create a destination folder (i.e. ISO) before running the command in Step 3. Type: mkdir D:\TempPE\ISO
  3. Run the following command to create a bootable ISO image:
    MakeWinPEMedia.cmd /iso D:\TempPE D:\TempPE\ISO\WindowServer_WinPE.iso

    How To Create a Custom WinPE Boot Image With PowerShell Support #PowerShell #Deploy #WindowsServer 6

PXE Boot with PowerShell Support

In the final section, you need to boot your physical machine from the ISO image that we created in the previous section using HPE, DELL EMC, or Cisco UCS virtual media drive.

The Physical machine will boot into WinPE with PowerShell support V5.1.16229.15 as showing in the following screenshot. With a little imagination, you can automate just about anything you can think of with PowerShell. Enjoy!

How To Create a Custom WinPE Boot Image With PowerShell Support #PowerShell #Deploy #WindowsServer 7

Stay tuned for the next post…

Thanks for reading!


Photo of author
About the Author
Charbel Nemnom
Charbel Nemnom is a Senior Cloud Architect, Swiss Certified ICT Security Expert, Certified Cloud Security Professional (CCSP), Certified Information Security Manager (CISM), Microsoft Most Valuable Professional (MVP), and Microsoft Certified Trainer (MCT). He has over 20 years of broad IT experience serving on and guiding technical teams to optimize the performance of mission-critical enterprise systems with extensive practical knowledge of complex systems build, network design, business continuity, and cloud security.

Related Posts


What’s New in Hyper-V in Windows Server Version 1709? #HyperV #WindowsServer #Windows10

How To Deploy Windows Server 2016 from VHDX on SD Cards with #PowerShell and WinPE #WindowsServer #HyperV


Let me know what you think, or ask a question...

error: Alert: The content of this website is copyrighted from being plagiarized! You can copy from the \'Code Blocks\' in \'Black\' by selecting the Code. Thank You!