# PowerShell – Environment Path is missing or overwritten

I had a strange issue today when I was doing some development where suddenly my scripts would report inability to…

blog

03 Nov 2018 pl

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

[Zobacz obrazy (6)](#pf-content-image-1-0)

I had a strange issue today when I was doing some development where suddenly my scripts would report inability to find some of my modules. Upon short investigation I found out $Env:PSModulePath is missing **“C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules”**

[!\[Wynik PowerShell pokazujący brakujący wpis PSModulePath\](/wp-content/uploads/2018/11/img_5bdd7228c01ad.png)](/wp-content/uploads/2018/11/img_5bdd7228c01ad.png)

As I've done only one thing – installing an update to AutoIt v3, it must have been during the install process that this value gets overwritten by AutoIt v3 installer. Seeing how C**:\Program Files (x86)\AutoIt3\AutoItX** is the only path displayed when checking **[Environment]::GetEnvironmentVariable(“PSModulePath”, “Machine”) **variable I'm reasonably sure AutoIt is at fault here. That means there are only two things to do. One is to report an issue to AutoIt to fix their Installer. Second is to set my** $Env:PSModulePath **to a proper value.

### 💡 What is the problem?

By default following paths are defined on Windows 10

[!\[Domyślne ścieżki modułów PowerShell w Windows 10\](/wp-content/uploads/2018/11/img_5bdd781a7f8a1.png)](/wp-content/uploads/2018/11/img_5bdd781a7f8a1.png)

In my case it's only showing one value

[!\[PowerShell pokazujący PSModulePath nadpisany jedną ścieżką AutoIt\](/wp-content/uploads/2018/11/img_5bdd78ede0a30.png)](/wp-content/uploads/2018/11/img_5bdd78ede0a30.png)

### 💡 How to fix this?

Following code provides a 3 step setup. First, it gets current value and displays it, and then it updates its, finally it shows you updated value. Feel free to do it in steps rather than one go.

[!\[Skrypt PowerShell przywracający PSModulePath\](/wp-content/uploads/2018/11/img_5bdd73d0a30b9.png)](/wp-content/uploads/2018/11/img_5bdd73d0a30b9.png)

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

Since AutoIt also overwritten other path **C:\Program Files\WindowsPowerShell\Modules **we need to rerun this twice with a different path. Running below code should give me my two missing paths along with AutoIt v3 PowerShell Module path.

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

[!\[Przywrócone wpisy PSModulePath w PowerShell\](/wp-content/uploads/2018/11/img_5bdd7b702aefa.png)](/wp-content/uploads/2018/11/img_5bdd7b702aefa.png)

That's it. If you reopen PowerShell session, you should have all paths available now, and all modules should work again.

[!\[Sesja PowerShell po ponownym uruchomieniu z przywróconymi ścieżkami modułów\](/wp-content/uploads/2018/11/img_5bdd7df948af5.png)](/wp-content/uploads/2018/11/img_5bdd7df948af5.png)

## Powiązane projekty

Projekty powiązane z tagami, kategoriami i treścią tego wpisu.

[Wszystkie projekty](/projekty/)

Trwa dopasowywanie projektów...

[Powrót do bloga](/blog/)

## Powiązane wpisy

- [Check an API write after a PowerShell timeout](/blog/verify-uncertain-api-outcomes-powershell/)
- [Inspect and convert mixed Office archives with PSWriteOffice](/blog/inspect-and-convert-mixed-office-archives-pswriteoffice/)
- [Compose PDF reports and automate page workflows with PSWriteOffice](/blog/automate-pdf-reports-and-page-workflows-pswriteoffice/)

<!-- PowerForge markdown artifact sha256:E14DF690FFA4CD48D2F60DE2B3C3BCCFE307BC9B8C8DF0E632AB37456A61EBEF -->
