【问题标题】:DSC - module does not exist at the PowerShell module pathDSC - PowerShell 模块路径中不存在模块
【发布时间】:2016-08-24 18:48:33
【问题描述】:

这是我遇到的错误:“PowerShell 提供程序 不存在于 PowerShell 模块路径中,也没有注册为 WMI 提供程序”

我不是 PowerShell 和 DSC 的新手,但我很难弄清楚这一点。我已按照指导 here 进行故障排除。我还发现了this almost identical question...唯一的解决办法似乎是重新启动(我试过了)。

所以我做了一个导入模块的配置,OctopusDSC。在对模块导入进行故障排除时,我遗漏了很多参数,但这是我所拥有的:

Configuration OctopusServer
{
    Import-DscResource -Module OctopusDSC

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

模块在本地和服务器上都存在于C:\Program Files\WindowsPowerShell\Modules

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

模块路径看起来不错(为了便于阅读,我在每个分号处添加了回车):

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

我可以拨打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}

我可以拨打Get-DscResource:

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

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

这是我的错误:

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

我错过了什么吗??

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

更新

我注意到此问题发生在安装了 Microsoft Monitoring Agent 的计算机上,但如果未安装该代理则不会发生。

安装后,PSModulePath 机器级环境变量如下所示(为清楚起见进行拆分):

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

如果我删除代理的路径,只留下C:\Windows\system32\WindowsPowerShell\v1.0\Modules\ 在那里,就会找到 OctopusDSC。我必须重新启动 WMI Provider Host 进程才能更改环境变量。如果我重新添加路径...失败。

现在这让我感到困惑,因为安装模块的实际路径一直是 C:\Program Files\WindowsPowerShell\Modules,并且可能是由 PowerShell 本身添加到计算出的 PSModulePath 中的(我假设是因为我通常不查看系统环境变量中设置的路径)。

我在其他地方看到在PSModulePath 中复制C:\Program Files\WindowsPowerShell\Modules 会导致模块解析出现问题。那么可能还有其他错误和敏感问题?

我觉得这是一个答案,但我仍在寻找解决方法,因为不建议删除该路径。

【问题讨论】:

  • 试试命令Get-DscResource看是否能发现cTentacleAgent。 Get-Module 只会显示它的容器,而不是资源。问题意味着资源在某种程度上无效,我可能会首先检查您的 PowerShell 版本(合理的期望等等)。
  • 刚刚试了一下...它找到了资源,但错误仍然存​​在:/。我用结果更新了我的问题。
  • 服务器上的PS版本?你能确保你的 DSC 资源不存在于 Program Files 以外的任何地方吗?
  • 版本 4...(在上面添加了表格)。我检查了C:\Windows\System32\WindowsPowerShell\v1.0\Modules,它不在里面。并且用户目录没有任何模块。

标签: powershell dsc


【解决方案1】:

作为健全性检查,请查看创建 .MOF 的目录...那里还有其他 MOF 文件吗? Start-DscConfiguration 在一个目录中运行所有 MOF。我重命名了我的 MOF 文件,但直到最终意识到错误出现在旧的 MOF 中,才使错误消失:(

【讨论】:

    【解决方案2】:

    这是 WMF 4.0 中的一个已知问题。您使用的是 WMF 4.0 吗?除非遇到 Andy 提到的 Windows 10 更新补丁问题,否则切换到 WMF 5.0 将解决此问题。

    【讨论】:

    • Server 2012 R2 提供的 WMF 4。是的,我想知道 WMF 5 是否有这个问题。
    【解决方案3】:

    你看到this post了吗?

    除了一些补丁(从 2015 年开始)之外,它还谈到了递归运行 unblock-file 的必要性。我想我以前遇到过。

    【讨论】:

      【解决方案4】:

      如果您运行的是 Windows 10,一个周年更新补丁打破了这一点(2016 年 8 月 25 日)。它应该在下周二修复。 http://www.zdnet.com/article/windows-10-update-breaks-powershell-and-microsoft-wont-fix-it-until-next-week/

      【讨论】:

        【解决方案5】:

        我遇到了同样的问题...原来我的问题是 Powershell 版本不匹配。我的工作站是第 5 版,但终点是第 4 版(开箱即用的 2012 R2)。

        在远程服务器上安装 WMF 5.1 后,它使用 xWebAdministration 模块识别并安装了 IIS。

        在此之前,我遇到了同样的错误,即他的模块不存在,即使我将它复制到了适当的路径。路径变量在另一个配置的 Web 服务器上是相同的。唯一不同的是 Powershell 版本。

        附带说明,我注意到'C:\Program Files\WindowsPowerShell\Modules' 不在任一服务器(或我的任何其他机器)的 $env:Path 变量中......只是'C:\Windows\system32\WindowsPowerShell\v1.0\Modules\' 的默认路径。其他东西必须允许 DSC 识别该位置的模块(即 Get-DscResource 在程序文件目录中找到模块,因为服务器在 WMF 5 上。而在 4 上,它只在 Windows 子文件夹中找到模块)。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2018-03-30
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-08-24
          • 1970-01-01
          • 2012-11-08
          • 2018-11-06
          相关资源
          最近更新 更多