Powershell DSC:无法加载模块xPSDesiredStateConfiguration
我正在阅读powershell.org上的DSC手册,并尝试使用手册中指定的配置代码设置拉取服务器Powershell DSC:无法加载模块xPSDesiredStateConfiguration,powershell,dsc,Powershell,Dsc,我正在阅读powershell.org上的DSC手册,并尝试使用手册中指定的配置代码设置拉取服务器 configuration CreatePullServer { param ( [string[]]$ComputerName = 'localhost' ) Import-DSCResource -ModuleName xPSDesiredStateConfiguration Node $ComputerName {
configuration CreatePullServer
{
param
(
[string[]]$ComputerName = 'localhost'
)
Import-DSCResource -ModuleName xPSDesiredStateConfiguration
Node $ComputerName
{
WindowsFeature DSCServiceFeature
{
Ensure = "Present"
Name = "DSC-Service"
}
xDscWebService PSDSCPullServer
{
Ensure = "Present"
EndpointName = "PSDSCPullServer"
Port = 8080
PhysicalPath = "$env:SystemDrive\inetpub\wwwroot\PSDSCPullServer"
CertificateThumbPrint = "AllowUnencryptedTraffic"
ModulePath = "$env:PROGRAMFILES\WindowsPowerShell\DscService\Modules"
ConfigurationPath = "$env:PROGRAMFILES\WindowsPowerShell\DscService\Configuration"
State = "Started"
DependsOn = "[WindowsFeature]DSCServiceFeature"
}
xDscWebService PSDSCComplianceServer
{
Ensure = "Present"
EndpointName = "PSDSCComplianceServer"
Port = 9080
PhysicalPath = "$env:SystemDrive\inetpub\wwwroot\PSDSCComplianceServer"
CertificateThumbPrint = "AllowUnencryptedTraffic"
State = "Started"
IsComplianceServer = $true
DependsOn = ("[WindowsFeature]DSCServiceFeature","[xDSCWebService]PSDSCPullServer")
}
}
}
CreatePullServer -ComputerName pull1.lab.pri
当我运行配置脚本时,powershell报告它无法加载XPSDiredStateConfiguration模块
无法导入DSCResource-ModuleName xPSDesiredStateConfiguration
加载模块“xPSDesiredStateConfiguration”:未找到模块
我已验证是否安装了DSC资源工具包,并且在执行Get DSCResource命令时列出了该模块。谁能给我一个线索,说明我可能做错了什么
另外,我使用的是64位Windows 7,并安装了KB2819745以将powershell升级到版本4。在回答对我原始问题的评论时,我检查了在执行
Get module-ListAvailable
时是否列出了模块。我注意到,当我运行命令时,它两次列出了包含模块的目录。然后我意识到,在试图解决之前的问题时,我将$env:ProgramFiles\WindowsPowerShell\Modules
目录添加到了PSModulePath
环境变量中,因此模块被复制并导致了问题。从PSModulePath
环境变量中删除路径后,一切正常 首先,您需要安装软件包。您可以从这里下载:
您的系统上是否有该模块?获取模块-列出它的列表。尽管你的建议确实让我找到了解决办法。我注意到,当我运行getmodule-listavable命令时,它两次列出了包含该模块的目录。在尝试解决之前的问题时,我已将$env:ProgramFiles\WindowsPowerShell\Modules目录添加到PSModulePath环境变量中,因此模块以某种方式被复制。这似乎是导致问题的原因,因为在我从PSModulePath环境变量中删除目录后,它就可以工作了。写了一句话“你需要安装这个软件包,下载这个为我工作”太棒了!你也应该接受这个答案,这样这个问题就不会出现没有答案的情况。@PortlandRunner他是问题的原始作者,回答了自己的问题,这是受到鼓励的。请注意,你建议删除一个完美的答案