【发布时间】:2016-08-24 18:48:33
【问题描述】:
这是我遇到的错误:“PowerShell 提供程序
我不是 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