# PowerShell – Environment Path is missing or overwritten

If PSModulePath is suddenly missing default module locations, PowerShell can stop discovering built-in or installed modules even though nothing seems broken at first glance.

blog

03 Nov 2018 es

![PowerShell – Environment Path is missing or overwritten](/wp-content/uploads/2018/11/ModulePathError.png)

[Ver imágenes (4)](#pf-content-image-1-0)

I ran into a strange development problem where PowerShell suddenly stopped finding modules that should have been available by default. The underlying issue turned out not to be the modules themselves, but the environment variable that tells PowerShell where to look for them:

`$Env:PSModulePath`

In my case, one of the expected default entries was missing:

`C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules`

[!\[PowerShell output showing the missing PSModulePath entry\](/wp-content/uploads/2018/11/img_5bdd7228c01ad.png)](/wp-content/uploads/2018/11/img_5bdd7228c01ad.png)

## Why this matters

PowerShell searches the directories listed in **PSModulePath** for modules. If one of the standard locations disappears, commands such as `Import-Module` or automatic module discovery can start failing in ways that feel random at first.

That is why this kind of issue is so annoying: the shell still opens, but pieces of your normal environment quietly stop working.

## What caused it here

The only recent change on that machine was an **AutoIt** update, so the suspicion was that its installer overwrote the machine-level `PSModulePath` instead of appending to it.

The symptoms fit that theory:

- expected default paths were gone
- only the AutoIt path remained in the machine-level variable

[!\[PowerShell showing PSModulePath overwritten to a single AutoIt path\](/wp-content/uploads/2018/11/img_5bdd78ede0a30.png)](/wp-content/uploads/2018/11/img_5bdd78ede0a30.png)

## Quick repair

The simplest recovery is to read the current value, append the missing path, and write it back:

```powershell
$MissingModule = "C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules"

# Display current value
$CurrentValue = [Environment]::GetEnvironmentVariable("PSModulePath", "Machine")
$CurrentValue

# Fix
[Environment]::SetEnvironmentVariable("PSModulePath", $CurrentValue + ";$MissingModule", "Machine")

# Display updated value
$UpdatedValue = [Environment]::GetEnvironmentVariable("PSModulePath", "Machine")
$UpdatedValue
```

If more than one default path is missing, repeat the process for the others you need restored.

Then split the value to verify what PowerShell will actually see:

```powershell
$UpdatedValue = [Environment]::GetEnvironmentVariable("PSModulePath", "Machine")
$UpdatedValue -split ';'
```

[!\[Restored PSModulePath entries in PowerShell\](/wp-content/uploads/2018/11/img_5bdd7b702aefa.png)](/wp-content/uploads/2018/11/img_5bdd7b702aefa.png)

After reopening PowerShell, module discovery should return to normal:

[!\[PowerShell session after restarting with all module paths restored\](/wp-content/uploads/2018/11/img_5bdd7df948af5.png)](/wp-content/uploads/2018/11/img_5bdd7df948af5.png)

## Better long-term lesson

The key takeaway is not just how to repair the variable once. It is that installers should **append** module paths, not replace the existing value.

If a product installer writes its own path as the full machine value, it can quietly break unrelated PowerShell workflows across the server or workstation.

## Current note

Microsoft still documents `PSModulePath` as the environment variable PowerShell uses to find module folders, and they also document that the **default paths differ between Windows PowerShell 5.1 and PowerShell 7**.

So if you troubleshoot this today, verify three things before restoring values blindly:

- which PowerShell version you care about
- whether the missing path belongs to **CurrentUser**, **AllUsers**, or `$PSHOME`
- whether you are repairing the **machine** or **user** value

That makes the fix cleaner and avoids restoring the wrong defaults for the wrong shell.

## Proyectos relacionados

Proyectos que encajan con las etiquetas, categorías y contenido de este artículo.

[Todos los proyectos](/es/proyectos/)

Buscando proyectos relacionados...

[Volver al blog](/blog)

## Artículos relacionados

- [PowerBGInfo 2.x: support-ready Windows backgrounds from PowerShell](/es/blog/powerbginfo-support-ready-windows-backgrounds/)
- [Track Ubiquiti Unifi Stock, and get notified of changes](/es/blog/simplify-notifications-about-ubiquiti-unifi-stock/)
- [PowerBGInfo – PowerShell alternative to Sysinternals BGInfo](/es/blog/powerbginfo-powershell-alternative-to-sysinternals-bginfo/)

<!-- PowerForge markdown artifact sha256:97B3E6ECBB14F783FDA222AFD223465994E2C6E8773671EF3D2DE0FA52C368D6 -->
