WinPE Problems

So you now have a WinPE Boot Image with PowerShell installed, everything works perfectly, as long as you stay contained working only with what's already installed and enabled in WinPE. The problem starts when you want to step out of the box and try to do something as basic as installing a PowerShell Module from the PowerShell Gallery.

PackageManagement is not installed

In the example below, this process fails because default ADK WinPE does not include PackageManagement.

PowerShell ExecutionPolicy is Restricted

Now let's say by some magic that you were able to get PackageManagement installed in your WinPE Boot Image, your next issue is that WinPE's default Execution Policy is Restricted. This is an easy fix, and there should be no issues setting this policy to Bypass.

Environment Variables

Now that the Execution Policy is resolved, another roadblock. The cause of the errors in the screenshot below are caused by $env:LOCALAPPDATA

Environment Variables can be displayed with the following PowerShell commnd

After running this command, its clear that a few Environment Variables and their values don't exist

Easy enough to fix

PowerShellGet is not up to date

The next problem with a simple Install-Module is because there are no PSRepositories, which is because PowerShellGet is version 1.0.0.1 and needs to be updated

Register PSRepository

Importing the PowerShellGet Module isn't enough, PSGallery needs to be registered

Making sure that we are using the new PowerShellGet version as the PackageProvider

PSGallery InstallationPolicy Trusted

Finally, the last piece of the puzzle is to set the Installation Policy to Trusted to make sure we can script this solution

PowerShell Profile

While this issue didn't prevent us from installing a module from PowerShell Gallery, its important to note that the PowerShell Profile for Current User is broken.

Typically, this would be the following path

This can easily be resolved by setting these variables.

User Shell Folders

The root cause of the PowerShell Profile issue is that some of the User Shell Folders do not exist, so you should make sure these paths exist and create them in your WinPE if they do not

Last updated