这是我遇到的错误:“PowerShell提供程序<module>在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
中(我假设因为我通常看不到该路径设置在系统环境变量)。
我在其他地方看到,在C:\Program Files\WindowsPowerShell\Modules
中复制PSModulePath
会导致模块解析出现问题。那么也许还有其他的错误和敏感性呢?
我觉得这是一个答案,但我仍在寻找一种解决方法,因为删除该路径不是首选。
作为一个完整性检查,请查看正在创建.MOF的目录...那里有其他MOF文件吗? Start-DscConfiguration运行目录中的所有MOF。我重命名了我的MOF文件,并且无法使错误消失,直到最终意识到错误是在旧的MOF中:(
这是WMF 4.0中的已知问题。你在使用WMF 4.0吗?切换到WMF 5.0将解决此问题,除非您遇到Andy提到的Windows 10更新补丁问题。
你看到this post了吗?
除了一些补丁(从2015年开始),它还讨论了递归运行unblock-file的必要性。我想我以前遇到过这种情况。
如果你正在运行Windows 10,那么周年纪念日更新补丁就会破坏(2016年8月25日)。应该在周二这个问题得到解决。 qazxsw poi
我遇到了同样的问题...事实证明我的问题是Powershell版本不匹配。我的工作站是版本5,但终点是版本4(2012 R2开箱即用)。
在远程服务器上安装WMF 5.1后,它使用xWebAdministration模块识别并安装了IIS。
在此之前,即使我将模块复制到适当的路径,我也得到了相同的错误,即模块不存在。路径变量在另一个配置的Web服务器上是相同的。唯一不同的是Powershell版本。
在旁注中,我注意到http://www.zdnet.com/article/windows-10-update-breaks-powershell-and-microsoft-wont-fix-it-until-next-week/不在任何服务器(或我的任何其他机器)的$ env:Path变量中......只是'C:\Program Files\WindowsPowerShell\Modules'
的默认路径。还有一些东西必须允许DSC识别该位置的模块(即Get-DscResource现在找到程序文件目录中的模块,因为服务器在WMF 5上。而在4上,它只在Windows子文件夹中找到了模块)。