Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DSC - module does not exist at the PowerShell module path

Tags:

powershell

dsc

This is the error I'm hitting: "The PowerShell provider <module> does not exist at the PowerShell module path nor is it registered as a WMI provider"

I'm not exactly a newbie to PowerShell and DSC, but I'm having a hard time figuring this one out. I have followed the guidance here for troubleshooting. I also found this almost identical question... the only resolution seemed to be rebooting (which I tried).

So I made a configuration which imports a module, OctopusDSC. I left out a lot of parameters during troubleshooting the module import, but here is what I have:

Configuration OctopusServer
{
    Import-DscResource -Module OctopusDSC

    Node "WIN-ABC123" 
    {
        cTentacleAgent OctopusTentacle 
        { 
            Ensure = "Present"
            State = "Started"
            Name = "Tentacle"
            ApiKey = ""
            OctopusServerUrl = ""
            DefaultApplicationDirectory = "C:\Utility"
        }
    }
}

The module exists in C:\Program Files\WindowsPowerShell\Modules both locally and on the server:

C:\>tree "C:\Program Files\WindowsPowerShell\Modules" /f
Folder PATH listing
Volume serial number is 9EC4-62C1
C:\PROGRAM FILES\WINDOWSPOWERSHELL\MODULES
└───OctopusDSC
    │   OctopusDSC.psd1
    │
    └───DSCResources
        └───cTentacleAgent
                cTentacleAgent.psm1
                cTentacleAgent.schema.mof

The module path seems fine (I put carriage returns in at each semi-colon, for readability):

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

I can call Get-Module:

PS C:\> Get-Module OctopusDSC -ListAvailable

    Directory: C:\Program Files\WindowsPowerShell\Modules

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Manifest   1.0.1      OctopusDSC                          {Get-TargetResource, Set-TargetResource, Test-TargetResource}

I can call Get-DscResource:

PS C:\temp> Get-DscResource  -Name "cTentacleAgent"

ImplementedAs   Name                      Module                         Properties
-------------   ----                      ------                         ----------
PowerShell      cTentacleAgent            OctopusDSC                     {Name, ApiKey, DefaultApplicationDirectory,...

And this is my error:

PS C:\> Start-DscConfiguration -Path .\OctopusServer -Verbose -WhatIf -Wait
What if: [WIN-ABC123]: LCM:  [ Start  Set      ]
What if: [WIN-ABC123]: LCM:  [ End    Set      ]
The PowerShell provider OctopusDSC does not exist at the PowerShell module path nor is it registered as a WMI provider.
    + CategoryInfo          : InvalidOperation: (root/Microsoft/...gurationManager:String) [], CimException
    + FullyQualifiedErrorId : ModuleNameNotFound
    + PSComputerName        : WIN-ABC123

Am I missing something??

PS C:\> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      4.0
WSManStackVersion              3.0
SerializationVersion           1.1.0.1
CLRVersion                     4.0.30319.34014
BuildVersion                   6.3.9600.16394
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion      2.2

Update

I noticed this problem happens on machines with Microsoft Monitoring Agent installed, but does not happen if that agent is not installed.

After the install, the PSModulePath machine-level environment variable looks like this (split for clarity):

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

If I remove the agent's path, and only leave C:\Windows\system32\WindowsPowerShell\v1.0\Modules\ in there, OctopusDSC is found. I do have to restart WMI Provider Host process to get the environment variable change to take. If I add the path back in... fail.

Now this is confusing to me because the whole time the actual path the module is installed in is C:\Program Files\WindowsPowerShell\Modules, and that is presumbably added to the calculated PSModulePath by PowerShell itself (I assume that because I typically don't see that path set up in the system environment variables).

I have seen elsewhere that duplicating C:\Program Files\WindowsPowerShell\Modules in PSModulePath can cause problems with module resolution. So maybe there are other bugs and sensitivities around it?

I feel like this is kind of an answer, but I am still looking for a workaround, as removing that path is not preferred.

like image 645
Jason Capriotti Avatar asked Aug 24 '16 18:08

Jason Capriotti


2 Answers

As a sanity check, look at the dir where your .MOF is being created...are there any other MOF files in there? Start-DscConfiguration runs all of the MOF's in a dir. I renamed my MOF file and could not make an error disappear until finally realizing the error was in the old MOF :(

like image 134
KevinC Avatar answered Oct 21 '22 12:10

KevinC


This is a known issue in WMF 4.0. Are you using WMF 4.0? Switching to WMF 5.0 would fix this issue unless you are hitting Windows 10 update patch issue mentioned by Andy.

like image 42
N.Gupta Avatar answered Oct 21 '22 13:10

N.Gupta