DSC推模式 - 复制DSC资源的最佳方式

问题描述 投票:4回答:5

我正在探索DSC并想知道将DSC资源复制到目标主机的最佳方法是什么?

当我尝试将配置推送到目标主机时,它抱怨缺少DSC资源。

The PowerShell DSC resource xWebAdministration does not exist at the PowerShell module path nor is it registered as a WMI DSC resource.
    + CategoryInfo          : InvalidOperation: (root/Microsoft/...gurationManager:String) [], CimException
    + FullyQualifiedErrorId : DscResourceNotFound
    + PSComputerName        : server1.appman.net
dsc
5个回答
7
投票

确保资源可用的最简单方法是设置基于文件共享的存储库以下拉模块。这个博客应该帮助你http://nanalakshmanan.com/blog/Push-Config-Pull-Module/


1
投票

我尝试使用DSC安装PS模块。它需要3个独立的配置:

Configuration InitialConfiguration
{
    Import-DscResource -ModuleName 'PSDesiredStateConfiguration'

    Node MyServer
    {
        Script InstallModule
        {
            SetScript = { Install-Module PackageManagement -MinimumVersion 1.1.7 -Force }
            TestScript = { $version = (Get-Module PackageManagement -ListAvailable).Version; $version.Major -ge 1 -and $version.Minor -ge 1 }
            GetScript = { Get-Module PackageManagement -ListAvailable }
        }
    }
}

Configuration ModulesConfiguration
{
    Import-DscResource -ModuleName 'PackageManagement' -ModuleVersion 1.1.7.0

    Node MyServer
    {
        PackageManagement xWebAdministration
        {
            Name = 'xWebAdministration'
        }
    }
}

Configuration WebServerConfiguration
{
    Import-DscResource –ModuleName 'xWebAdministration'

    Node MyServer
    {
        xWebAppPool SampleAppPool
        {
            Name = 'SampleAppPool'
        }
    }
}

但是,Microsoft使用simple script在其example中使用WinRM安装模块。


0
投票

创建将安装模块的DSC配置,并且可以从网络共享或更多模块中获取模块,也可以从某些存储库(例如git)中检出它们,但当然如果他们可以访问它。推或拉什么更适合你。


0
投票

在PSModule路径中找不到模块时出现错误。 使用以下行从PSGallery存储库Install-Module -Name xWebAdministration安装xWebAdministration powershell模块

然后在弹出窗口时单击“Yes to All”,模块安装完毕 要交叉检查模块是否已安装,请在powershell控制台中键入$env:PSModulePath并在PS Module路径中找到xWebAdministration文件夹


0
投票
# Commands for pushing DSC Resource Modules to Target Nodes.
# Resources you want to push must be available on this Authoring Machine.

#Required DSC resource modules
$moduleNames = "XWebAdministration", "xSMBShare", "cNtfsAccessControl", "OctopusDSC", "PSDSCResources", "DSCR_Font"

#ServerList to push files to
$Servers = "C:\temp\serverList.txt"
$serverList = (get-content $Servers |
    Where { $_ -notlike ";*" } | #lines that start with ';' will be considered comments
    ForEach { $_ } |
    select -Unique `
)

foreach ($server in $serverList)
{
    $Session = New-PSSession -ComputerName $server

    $getDSCResources = Invoke-Command -Session $Session -ScriptBlock {
        Get-DscResource
    }

    foreach ($module in $moduleNames)
    {
        if ($getDSCResources.moduleName -notcontains $module){
            #3. Copy module to remote node.
            $Module_params = @{
                Path = (Get-Module $module -ListAvailable).ModuleBase
                Destination = "$env:SystemDrive\Program Files\WindowsPowerShell\Modules\$module"
                ToSession = $Session
                Force = $true
                Recurse = $true
                Verbose = $true

            }

            Copy-Item @Module_params
        }
    }
    Remove-PSSession -Id $Session.Id
}
© www.soinside.com 2019 - 2024. All rights reserved.