# PSModulePath problems... unable to load modules

**URL:** <https://forums.powershell.org/t/psmodulepath-problems-unable-to-load-modules/7069>\
**Category:** DSC\
**Created:** [August 25, 2016, 12:10pm UTC](https://forums.powershell.org/t/psmodulepath-problems-unable-to-load-modules/7069 "2016-08-25T12:10:58Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jason-capriotti](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/jason-capriotti/32/600_2.png) [@jason-capriotti](https://forums.powershell.org/u/jason-capriotti)\
**Post date:** [August 25, 2016, 12:10pm UTC](https://forums.powershell.org/t/psmodulepath-problems-unable-to-load-modules/7069/1 "2016-08-25T12:10:58Z")

</div>

I started an [SO thread](http://stackoverflow.com/questions/39130930/dsc-module-does-not-exist-at-the-powershell-module-path) yesterday and since then traced the problem to what appears to have something to do with PSModulePath.

There is a lot of detail in the SO post, but I think this summarizes it:

- I have a DSC module installed to **C:\Program Files\WindowsPowerShell\Modules**
- Installing Microsoft Monitoring Agent causes this DSC module to fail to load with an error: "The PowerShell provider does not exist at the PowerShell module path nor is it registered as a WMI provider"
- I _think_ this has to do with the agent adding a path (C:\Program Files\Microsoft Monitoring Agent\Agent\PowerShell) to the system-level PSModulePath variable.
- If I remove that path from PSModulePath system environment variable, the DSC module can again be found.
- At all time (both with and without that path in PSModulePath, outputting $env:PSModulePath shows **C:\Program Files\WindowsPowerShell\Modules** in the list, so I'm at a loss as to why the module would not be found.

I’ve seen elsewhere that duplicating paths in PSModulePath can lead to problems with modules loading, but this seems different, yet related as PSModulePath seems very sensitive…

Has anyone else seen problems like this? Is there a way to call Import-DscModule using a specific path?

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [August 26, 2016, 3:08pm UTC](https://forums.powershell.org/t/psmodulepath-problems-unable-to-load-modules/7069/2 "2016-08-26T15:08:14Z")

</div>

The logic that uses the environment variable is indeed a little picky, although I’ve not seen it behave that way before.

What’s the complete environment variable text with the Agent’s path in there?

---

<div class="post-metadata">

**Author:** ![silent-steel](https://avatars.discourse-cdn.com/v4/letter/s/e5b9ba/32.png) [@silent-steel](https://forums.powershell.org/u/silent-steel)\
**Post date:** [August 26, 2016, 3:44pm UTC](https://forums.powershell.org/t/psmodulepath-problems-unable-to-load-modules/7069/3 "2016-08-26T15:44:18Z")

</div>

Normally windows searches paths according to position, if you have the  
C:\Program Files\WindowsPowerShell\Modules at the start is one way to see if your issues stop.  
Path bloating has always been a problem in Windows.

Do note that it works both ways as the monitoring agent might be behaving silly but its unlikely.

One way to avoid it is simply hardcoding the path to your module as Import-Module accepts full paths and maximum and minimum versions (if needed)

so using

Import-Module C:\myDirectory\myModule

with full path to the module, might help as well

---

<div class="post-metadata">

**Author:** ![jason-capriotti](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/jason-capriotti/32/600_2.png) [@jason-capriotti](https://forums.powershell.org/u/jason-capriotti)\
**Post date:** [August 30, 2016, 3:25pm UTC](https://forums.powershell.org/t/psmodulepath-problems-unable-to-load-modules/7069/4 "2016-08-30T15:25:20Z")

</div>

Don -  
Here you go… non-working version.

```
PS C:\> $env:PSModulePath
C:\Users\jasonc\Documents\WindowsPowerShell\Modules;C:\Program Files\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules\;C:\Program Files\Microsoft Monitoring Agent\Agent\PowerShell\

PS C:\> [environment]::GetEnvironmentVariable("PSModulePath","Machine")
C:\Windows\system32\WindowsPowerShell\v1.0\Modules\;C:\Program Files\Microsoft Monitoring Agent\Agent\PowerShell\

PS C:\> [environment]::GetEnvironmentVariable("PSModulePath","Process")
C:\Users\jasonc\Documents\WindowsPowerShell\Modules;C:\Program Files\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules\;C:\Program Files\Microsoft Monitoring Agent\Agent\PowerShell\
```

Basically, if I take out **;C:\Program Files\Microsoft Monitoring Agent\Agent\PowerShell\</strong\> using the System -\> Advanced system settings UI and restart WmiPrvSE, it works.**

 

**This is what it looks like then (also restarting shell):**

 
**```
PS C:\> $env:PSModulePath
C:\Users\jasonc\Documents\WindowsPowerShell\Modules;C:\Program Files\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules\**

**PS C:\> [environment]::GetEnvironmentVariable("PSModulePath","Machine")
C:\Windows\system32\WindowsPowerShell\v1.0\Modules\**

**PS C:\> [environment]::GetEnvironmentVariable("PSModulePath","Process")
C:\Users\jasonc\Documents\WindowsPowerShell\Modules;C:\Program Files\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules\
```**

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [August 30, 2016, 4:44pm UTC](https://forums.powershell.org/t/psmodulepath-problems-unable-to-load-modules/7069/5 "2016-08-30T16:44:53Z")

</div>

Can you manually load all the modules from that Agent, by specifying their path? My guess is that one if them is broken, or has a bad manifest, and it’s making autodiscovery explode.

---

<div class="post-metadata">

**Author:** ![jason-capriotti](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/jason-capriotti/32/600_2.png) [@jason-capriotti](https://forums.powershell.org/u/jason-capriotti)\
**Post date:** [August 30, 2016, 7:45pm UTC](https://forums.powershell.org/t/psmodulepath-problems-unable-to-load-modules/7069/6 "2016-08-30T19:45:56Z")

</div>

I’m not sure what you mean by loading the modules by specifying the path. I can call **Import-Module OctopusDSC** (the module in question).

I decided to try generating the MOF on the server, which I assume would require being able to find the module. That worked… but of course **Start-DscConfiguration** did not work.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 9:16pm UTC](https://forums.powershell.org/t/psmodulepath-problems-unable-to-load-modules/7069/7 "2024-05-16T21:16:56Z")

</div>

Closed on May 16, 2024, 9:16pm UTC


