Author Posts

August 25, 2016 at 5:40 pm

I started an SO thread 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?

August 26, 2016 at 8:38 pm

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?

August 26, 2016 at 9:14 pm

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

  • This reply was modified 1 year, 11 months ago by  Arie H.

August 30, 2016 at 8:55 pm

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

August 30, 2016 at 10:14 pm

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.

August 31, 2016 at 1:15 am

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.