Powershell DSC:无法加载模块xPSDesiredStateConfiguration

Dom*_*min 6 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
Run Code Online (Sandbox Code Playgroud)

当我运行配置脚本时,powershell报告它无法加载xPSDesiredStateConfiguration模块.

Import-DSCResource -ModuleName xPSDesiredStateConfiguration无法加载模块'xPSDesiredStateConfiguration':找不到模块.

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

此外,我使用的是Windows 7 64位并安装了KB2819745,以便将PowerShell升级到版本4.

Dom*_*min 9

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