WinPE: Adding Windows PowerShell support to Windows PE

You can add PowerShell support to WinPE, which can be used to help automate Windows deployment.

Note

For Arm64 Windows PE, substitue 'Arm64' for 'AMD64' in the sample commands and folder path shown below.

Prepare a local copy of the Windows PE files

On a technician PC:

  1. Download and install the Windows Assessment and Deployment Kit (ADK) and matching WinPE add-on.

    For ADK versions prior to Windows 10, version 1809, WinPE is part of the ADK and isn't a separate add-on.

  2. Start the Deployment and Imaging Tools Environment as an administrator.

  3. Create a working copy of the Windows PE files:

    copype amd64 C:\WinPE_amd64_PS
    

    See CopyPE command line options for more information.

Add WinPE PowerShell optional components

Now that you have a working set of files that includes a WinPE image, you can mount the image and add the WinPE optional components required to add PowerShell.

Use the following script to mount the Windows image, add the Windows PE optional components for Windows PowerShell, and to unmount the image.

  1. Mount your WinPE image:

    Dism /Mount-Image /ImageFile:"C:\WinPE_amd64_PS\media\sources\boot.wim" /Index:1 /MountDir:"C:\WinPE_amd64_PS\mount"
    
  2. Add the required optional components to your image. The example below shows the components to add to an image with the en-US language. If your image has additional languages, also add the versions of the packages below for the other languages included in your image.

    Dism /Add-Package /Image:"C:\WinPE_amd64_PS\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_PS\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_PS\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_PS\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_PS\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_PS\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_PS\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_PS\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_PS\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_PS\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_PS\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_PS\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"
    
  3. Unmount your image, committing changes:

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

Install this version of Windows PE to a USB key

Now that you have a WinPE image that includes PowerShell, you can create bootable WinPE media.

  1. Insert a USB drive into your technician PC.

  2. Run MakeWinPEMedia to create a bootable USB key that includes your WinPE image:

    MakeWinPEMedia /UFD C:\WinPE_amd64_PS F:
    

    Warning

    MakeWinPEMedia will format your USB drive and erase any existing content. Make sure that your USB drive doesn't contain any files or information that you want to keep.

Start Windows PowerShell in Windows PE

  1. Boot a PC into WinPE using the WinPE bootable media that you created.

  2. From the WinPE command line, start Windows PowerShell:

    X:\Windows\system32\WindowsPowerShell\v1.0\powershell
    

WinPE overview

WinPE: Add packages (Optional Components Reference)

WinPE: Create USB Bootable drive

WinPE: Create a Boot CD, DVD, ISO, or VHD

WinPE: Mount and Customize