How do I publish modules from the DSC Pull Server

2015-10-12T20:00:00Z

One of the huge advantages of using a Desired State Configuration Pull Server is the ability to easily distribute resources to subscribed client nodes.

For this example, I've installed the xSmbShare module locally. The first step is then creating an archive for our module:

PS \> Add-Type -A System.IO.Compression.FileSystem
PS \> [IO.Compression.ZipFile]::CreateFromDirectory('C:\Windows\System32\WindowsPowerShell\v1.0\Modules\DSCResources\xSmbShare', "$env:TEMP\xSmbShare_1.0.zip")

Move the archive to the DSC Pull Server:

PS \>  Move-Item -Path $env:TEMP\xSmbShare_1.0.zip -Destination \\dc1.biscuit.ninja\c$\DSCPullServer\Modules\.

Add a checksum for the module to the DSC push server:

PS \>  New-DSCCheckSum -path \\dc1.biscuit.ninja\c$\DSCPullServer\Modules -force

I managed to waste twenty or so minutes whilst creating resources to be published via the Pull server due to a comment I'd read on this PowerShell blog. The blog itself gives a naming convention of "ModuleName_Version.zip". A comment by Ethan suggests that this should be "..zip". I'd noted Ethan's comment and originally named the xSmbShare module "xSmbShare.1.0.zip" Unfortunately that didn't work. I was seeing the following error in my output:

Invoke-CimMethod : Cannot find module xSmbShare.1.0 from the server http://win2k12r2-dc1:8080/PSDSCPullServer.svc//Module(ConfigurationId='1a5a3314-35b0-41c1-a439-16fb21716537',ModuleName='xSmbShare',ModuleVersion='1.0')/ModuleContent

I ran Sysinternal's Process Monitor and quickly discovered that the pull server was in fact looking for "xSmbShare_1.0.zip", not "xSmbShare.1.0.zip". Maybe there's some inconsistency here between different versions of WMF.

Finally, there's one more gotcha that you may run into. With the incorrect local configuration manager sessints on the target nodes, you might see errors like:

Invoke-CimMethod : Installation of module xSmbShare failed since the module directory already exists at C:\Program Files\WindowsPowerShell\Modules\xSmbShare

Tweak the local configuration manager settings on the target nodes so that DSC Resources can be overwritten if they already exist. They key component in the LCM configuration is the 'AllowModuleOverwrite' key that should be set to 'True':

Configuration SetPullMode
{
    Node <NodeName>
    {
        LocalConfigurationManager
        {
            ConfigurationMode = 'ApplyAndAutocorrect'       # Necessary to push updates to the compliance server
            RefreshFrequencyMins = 5                        # For testing purposes - means we don't have to wait
                                                            # too long to see results in the compliance server
            ConfigurationID = "8f5016dc-052c-4a01-9c84-8dcea37c9ab1"
            RefreshMode = ‘Pull’
            DownloadManagerName = ‘WebDownloadManager’
            DownloadManagerCustomData = @{
                ServerUrl = ‘http://PullServerName>/PSDSCPullServer.svc/’;
                AllowUnsecureConnection = ‘True’ }
            AllowModuleOverwrite = 'True'                   # Prevent errors when refreshing modules    
        }
    }
}
PS \>  SetPullMode
PS \>  Set-DSCLocalConfigurationManager –Compute <NodeName> -Path ./SetPullMode –Verbose

If you've landed here courtesy of your preferred search engine, then perhaps you'd like to read the main article.