4

I'm exploring DSC and wondering what's the best way to copy DSC resources to target host ?

When I try to push my configuration to the target host, It complain of missing DSC resource.

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
Philip K. Adetiloye
  • 3,102
  • 4
  • 37
  • 63

5 Answers5

7

The easiest way to ensure resources are available is to setup a file share based repository for pulling down modules. This blog should help you out http://nanalakshmanan.com/blog/Push-Config-Pull-Module/

Nana Lakshmanan
  • 741
  • 3
  • 6
2

I tried to install PS modules using DSC. It requires 3 separate configurations:

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'
        }
    }
}

However, Microsoft uses simple script to install modules using WinRM in their example.

Der_Meister
  • 4,771
  • 2
  • 46
  • 53
0

Create DSC configuration that will install modules, and modules can be taken from network share or more maybe may check out them from some repository like git but of course if they will have access to it. Push or pull whats better fit You.

Janusz Nowak
  • 2,595
  • 1
  • 17
  • 36
0

The error comes when module is not found in PSModule paths.
Use the following line to install xWebAdministration powershell module from PSGallery repository Install-Module -Name xWebAdministration

Then click "Yes to All" when a pop up comes, the module gets installed
To crosscheck if the module got installed, type $env:PSModulePath in powershell console and find xWebAdministration folder in PS Module paths

stej
  • 28,745
  • 11
  • 71
  • 104
  • This is assuming your node has access to the internet. And so manual in your explanation. #automateallthethings – Brettski May 18 '18 at 15:16
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
}
jhwk6957
  • 1
  • 1
  • 1
    Hi, welcome to Stack Overflow. When answering a question that already has many answers, please be sure to add some additional insight into why the response you're providing is substantive and not simply echoing what's already been vetted by the original poster. This is especially important in "code-only" answers such as the one you've provided. – chb Feb 16 '19 at 02:32