Build a PowerShell-Enabled Windows PE Key: Part 4
Summary: Build out the necessary file structure for a Windows PE environment.
Honorary Scripting Guy, Sean Kearney, is here today to give you all you need to build out your own Windows PE file structure.
Note This is a five-part series that includes the following posts:
- Build a PowerShell-Enabled Windows PE Key: Part 1
Install the Windows ADK and validate its presence with Windows PowerShell
- Build a PowerShell-Enabled Windows PE Key: Part 2
Customize a Windows PE environment to contain Windows PowerShell and DISM modules
- Build a PowerShell-Enabled Windows PE Key: Part 3
Identify available USB keys and make them bootable devices
- Build a PowerShell-Enabled Windows PE Key: Part 4
Build out the necessary file structure for a Windows PE environment
- Build a PowerShell-Enabled Windows PE Key: Part 5
Populate a bootable USB key with content from Windows PE
Let’s think about what we’ve developed in the first three parts of this series:
- One Windows ADK environment for Windows 10.
- One customized Windows PE WIM file with Windows PowerShell.
- One prepared bootable USB key.
Our next task is to pull all of this together into a file structure for Windows PE.
Normally, we would take a Windows image file and expand it directly to the target file system. But not with Windows PE. A Windows PE environment boots from a very tiny version of Windows. It then creates a RAM drive (think back to the days of DOS!) and places the WIM file structure within the RAM drive.
Fortunately, we don’t need to do any work, the file structure is readily built for us. If you examine the folder structure for Windows PE, you’ll see a folder called Media. This is located directly under your AMD64 or x86 folder, depending upon the chosen version of Windows PE.
In our case, we are working with the 64-bit version, which means the folder you need to grab is:
C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\Media
If you use our previous function and $Variables, you can reference it in this fashion:
We now need somewhere to put the file structure of Windows PE, so let’s use this:
New-Item -ItemType Directory -Path $WinPETemp –Force
Copy-Item -Path “$WinAdk\Media” -Destination $WinPETemp -Recurse –Force
New-Item -ItemType Directory -Path “$WinPETemp\Media\Sources” –Force
Copy-Item -path “$WinAdk\en-us\winpe.wim” -Destination “$WinPETemp\Media\Sources\boot.wim”
If you did nothing else, you’d have yourself a very basic structure for Windows PE under the folder called Media that is defined within $WinPETemp.
The critical file is called Boot.wim and it is under the Sources folder. We need to update this file with the customized version we created in Part 2 of this series. Remember these three lines of PowerShell?
New-Item -Path $Destination -ItemType Directory –Force
Copy-Item -path “$WinPETemp\Media\boot.wim” -destination “$Destination\”
We’ll need to copy the Boot.wim from the folder defined in $Destination to the Sources folder:
Copy-Item –path “$Destination\boot.wim” –destination “$WinPETemp\Media\Sources” –force
This folder structure will now have everything you need for using Windows PE with Windows PowerShell. Our next phase?
We get that puppy on a USB key and start to play…tomorrow!
I invite you to follow the Scripting Guys on Twitter and Facebook. If you have any questions, send email to them at email@example.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then always remember that with great PowerShell comes great responsibility.
Sean Kearney, Honorary Scripting Guy, Cloud and Datacenter Management MVP