PSModulePath problems... unable to load modules

This topic contains 5 replies, has 3 voices, and was last updated by Profile photo of Jason Capriotti Jason Capriotti 3 months, 1 week ago.

  • Author
    Posts
  • #51922
    Profile photo of Jason Capriotti
    Jason Capriotti
    Participant

    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?

  • #52161
    Profile photo of Don Jones
    Don Jones
    Keymaster

    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?

    • #52618
      Profile photo of Jason Capriotti
      Jason Capriotti
      Participant

      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\
      
  • #52175
    Profile photo of Arie H
    Arie H
    Participant

    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 3 months, 1 week ago by Profile photo of Arie H Arie H.
  • #52630
    Profile photo of Don Jones
    Don Jones
    Keymaster

    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.

  • #52639
    Profile photo of Jason Capriotti
    Jason Capriotti
    Participant

    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.

You must be logged in to reply to this topic.