Import-DscResource

Hi,

Within my DSC script in using a xDSC resource but i need to import this module onto the destination host. Is it possible to use DSC to copy the module to the destination and import all within a single script? or do i need to create to scripts, 1 to import the module and then the DSC script?

Hope that makees sense?

Thanks

Tom

If you’re using Push, the resources need to exist on the destination before you start-DSCConfiguration. If you’re using pull, they need to exist on the pull server.

If you are using Pull you need to zip all the modules for the destination server.
I used the following to zip all folders.

$modules = (Get-ChildItem "c:\Program Files\WindowsPowerShell\Modules\").Name
foreach ($module in $modules) {
    foreach ($version in ((Get-ChildItem "c:\Program Files\WindowsPowerShell\Modules\$module").Name)) {
        $ZipPath = 'C:\Program Files\WindowsPowerShell\DscService\Modules\' + $module + '_' + $version + '.zip'
        Compress-Archive -Path "c:\Program Files\WindowsPowerShell\Modules\$module\$version\*" -DestinationPath $ZipPath -Verbose
    }
}

Hi,

Thanks for the replies, So is there a way to run multiple “start-dscconfiguration” scripts within 1 script.

So the first script will import all the mondules and the the second script will run the next config.

Thanks

TommyQuality.

Hi,

If you are using Push the modules already need to be on the destination server as Missy Januszko said.
So you have to manually move the modules to destination before running Start-DSCConfiguration.

In theory, yes, you could run first one Start-DSCconfiguration that copy over the modules, and then a second that do what you want it to do.

Simon

Why would you use more then one Start-DSCConfiguration ?

the idea behind DSC is that once you set a node via push or pull, the node will consistently stay at that state.

What you want is something to copy a file and then use it via a start-DSCConfiguration that will run later

You can achieve that in normal PowerShell, vbscript, batch, or what ever language you want…has nothing to do with DSC.

It will actually be a waste to do it in a DSC if all you want is to copy files if a second after that you push a newer DSC configuration.

Keep DSC for state you want a node to be in.

Hi,

Part of my job is continuously refresh test environments with copies of our production systems, and as part of the refresh the servers need certain configurations applied which I do with multiple xDSC resources.

I manually push the 1st DSC script to install various windowsfeatures, creates folders and copies files, user accounts, and also copies across the xdsc modules/resources which are needed.
The I then push the second script that uses the xdsc modules made available by the first script and finishes the configuration, like amending IIS permission or local security polices. These can then be re-run to keep the correct node state.

I know I can do this with PowerShell, but it’s so easy with DSC.

So basically what I am asking, was there a way to trigger the first DSC and then the second without me manually running the 2nd.

Cheers,

Tommy

Hi Arie H,

I see what you are staying, so it would be better to have a PS script run to just push the modules, and then 1 DSC script to configure the node.

Thanks

Tommy

Why not just put the xDSC module on a Pull server, and then get the nodes to pull it when they update their configuration?

Set the nodes to Pull and then just use Update-DSCConfiguration

You can use a DSC feature called ‘Push to Pull’. Basically you can push the configuration but can still configure LCM to automatically download the modules when needed from either file based pull server or web based pull server. LCM settings would look something like:

[DscLocalConfigurationManager()]
configuration PushToPull
{
    Settings
    {
        RefreshMode = 'Push'
    }
    ResourceRepositoryShare share1
    {
        SourcePath = $sourcePath
    }
}