PSModulePath problems... unable to load modules

Welcome Forums DSC (Desired State Configuration) PSModulePath problems... unable to load modules

Viewing 4 reply threads
  • Author
    Posts
    • #51922
      Participant
      Topics: 1
      Replies: 5
      Points: 2
      Rank: Member

      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
      Keymaster
      Topics: 13
      Replies: 4872
      Points: 1,844
      Helping HandTeam Member
      Rank: Community Hero

      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
        Participant
        Topics: 1
        Replies: 5
        Points: 2
        Rank: Member

        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
      Participant
      Topics: 5
      Replies: 261
      Points: -19
      Rank: Member

      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

    • #52630
      Keymaster
      Topics: 13
      Replies: 4872
      Points: 1,844
      Helping HandTeam Member
      Rank: Community Hero

      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
      Participant
      Topics: 1
      Replies: 5
      Points: 2
      Rank: Member

      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.

Viewing 4 reply threads
  • The topic ‘PSModulePath problems... unable to load modules’ is closed to new replies.