2014-10-02 44 views
6

我正在通过powershell.org的DSC书,并尝试使用本书中指定的配置代码设置拉服务器。Powershell DSC:无法加载模块xPSDesiredStateConfiguration

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的报告,它是无法加载xPSDesiredStateConfiguration模块。

进口DSCResource -ModuleName xPSDesiredStateConfiguration无法 加载模块 'xPSDesiredStateConfiguration':模块未找到。

我确认已安装了DSC资源工具包,并且在执行Get-DSCResource命令时列出了该模块。任何人都可以给我一个线索,说明我可能做错了什么?

此外,我使用的是Windows 7,并且已安装KB2819745把PowerShell的最高版本为4

+0

是您系统上的模块吗? Get-Module -ListAvailible – Schwarzie2478 2014-10-02 14:51:17

+1

是的,它被列出。 尽管您的建议确实使我走上了解决方案的道路。我注意到当我运行Get-Module-ListAvailable命令时,它列出了包含该模块两次的目录。在试图解决早期问题时,我已经将$ env:ProgramFiles \ WindowsPowerShell \ Modules目录添加到PSModulePath环境变量中,因此模块以某种方式被复制。看来这是造成这个问题的原因,因为它在我从PSModulePath环境变量中删除目录后工作。 – Domin 2014-10-02 15:05:55

回答

9

在回答我原来的问题评论64位,我检查执行Get-Module -ListAvailable时正在列出的模块。我注意到,当我运行命令时,它列出了包含模块两次的目录。然后我意识到,在试图解决早期问题时,我已将$env:ProgramFiles\WindowsPowerShell\Modules目录添加到PSModulePath环境变量中,因此模块被复制并导致问题。从PSModulePath环境变量中删除路径后,一切正常!

+1

太棒了!你也应该接受这个答案,以便这个问题不会出现没有答案。 – briantist 2014-10-02 15:32:33

+0

@PortlandRunner他是最初的问题作者并回答了他自己的问题,这在SO中得到了鼓励。请注意,你建议删除一个非常好的答案 – Devin 2014-10-18 01:37:42