8

我正在阅读 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 模块。

Import-DSCResource -ModuleName xPSDesiredStateConfiguration 无法加载模块“xPSDesiredStateConfiguration”:找不到模块。

我确认我已经安装了 DSC 资源工具包,并且在我执行 Get-DSCResource 命令时会列出该模块。谁能告诉我我可能做错了什么?

另外,我使用的是 64 位 Windows 7 并安装了 KB2819745 以将 powershell 升级到版本 4。

4

2 回答 2

10

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

于 2014-10-02T15:08:37.797 回答
1

首先,您需要安装软件包。你可以在这里下载:

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

于 2020-11-30T12:39:36.130 回答