# 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.

<figure><img src="/files/ENRn8j1CZVpL8IywAN81" alt=""><figcaption></figcaption></figure>

## 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.

<figure><img src="/files/rZiARfgKTpKrDCIR7zjH" alt=""><figcaption></figcaption></figure>

## 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`

<figure><img src="/files/qpIKwLwpM9CtHLv2WSl8" alt=""><figcaption></figcaption></figure>

Environment Variables can be displayed with the following PowerShell commnd

```powershell
Get-ChildItem env:
```

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

<figure><img src="/files/FlPqAweovYhB0YmIGh9H" alt=""><figcaption></figcaption></figure>

```
APPDATA = X:\windows\system32\config\systemprofile\AppData\Roaming
HOMEDRIVE = X:
HOMEPATH = \windows\system32\config\systemprofile
LOCALAPPDATA = X:\windows\system32\config\systemprofile\AppData\Local
```

Easy enough to fix

<figure><img src="/files/2MYOpky1LZC4G7YwWsT4" alt=""><figcaption></figcaption></figure>

## 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

<figure><img src="/files/n6gG93zFLFjjh29rXadU" alt=""><figcaption></figcaption></figure>

## Register PSRepository

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

<figure><img src="/files/swcZHongsQIHr7JWCQXO" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/8EtA0MUvEFKobAZLpYkI" alt=""><figcaption></figcaption></figure>

## 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
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
```

<figure><img src="/files/fBjsu7u4byQMl5yco4iD" alt=""><figcaption></figcaption></figure>

## 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.

<figure><img src="/files/DzSSk3dqOu1WJkIT8kOJ" alt=""><figcaption></figcaption></figure>

Typically, this would be the following path

```
$HOME\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
```

This can easily be resolved by setting these variables.

<figure><img src="/files/lwRHOeKi9G4GVyBIuvG6" alt=""><figcaption></figcaption></figure>

## 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

```
$env:UserProfile\AppData\Local
$env:UserProfile\AppData\Roaming
$env:UserProfile\Desktop
$env:UserProfile\Documents\WindowsPowerShell
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.osdeploy.com/inside-winpe/winpe-problems.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
