Powershell DSC:无法加载模块xPSDesiredStateConfiguration

时间:2014-10-02 14:22:37

标签: powershell dsc

我正在使用powershell.org的DSC书籍,尝试使用本书中指定的配置代码设置拉取服务器。

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 64位并安装了KB2819745,以便将PowerShell升级到版本4。

2 个答案:

答案 0 :(得分:9)

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

答案 1 :(得分:1)

首先,您需要安装该软件包。您可以从此处下载:

https://gallery.technet.microsoft.com/xPSDesiredStateConfiguratio-417dc71d