Menu

Virtual Geek

Tales from real IT system administrators world and non-production environment

Part 3: Configure PowerShell DSC Local configuration manager LCM in pull mode and update configuration

This is last part of configuring individual clients local configuration manager (LCM) in DSC pull mode so they can get and retrieve configuration copy every certain refresh frequency mode. You can treat LCM as an agent and it is by default there in on every system. where at least Poweshell version 4 exist. In script code lines of 2 to 22, I have provided main parameter ServerUrl is taken from as mentioned in Part 1

Part 1: Build your first Microsoft PowerShell DSC pull server
Part 2: Generate target server node config for PowerShell DSC pull server
Part 3: Configure PowerShell DSC Local configuration manager LCM in pull mode and update configuration
How to force a PowerShell DSC client to refresh configuration from pull server

powershell dsc, desired state configuration LCM, local configuration manager, set-dsclocalconfigurationmanager, get-dscconfigurationstatus, update-dscconfiguration, apply pull  mode, refreshfrequency min, server url

Line 25 and 26: Generates .mof file and keeps in the location c:\temp. Required parameter are Servername and Guid, Guid is taken from my earlier article Part 2 (All parts are related to each other). 

Line 29: Set-DSCLocalConfigurationManager start applying configuration to LCM and apply settings from pull server. Before make sure you enable winrm psremoting on DSC server and clients using POWERSHELL PS REMOTING BETWEEN STANDALONE WORKGROUP COMPUTERS, It is one of the prerequisite.

Line 32 -33: If you change configuration on pull server, it can be updated using cmdlet Update-DscConfiguration. This cmdlet connects to a pull server, downloads the configuration if it differs from what is current on the node, and then applies the configuration to the computerand Get-DscConfigurationStatus cmdlet retrieves detailed information about completed configuration runs on the system. By default, it returns the information about the last configuration run. This cmdlet is useful for finding historical information about configuration runs, such as when the configurations were run, the status of the runs, the number of resources in the configurations, and which resources succeeded or failed.

I can verify and see this configuration is updated successful as below configuration. 

Microsoft windows Powershell dsc desired state pull configuration client update-dscconfiguration, lcm, local configuration manager, Set-DscLocalConfigurationManager, Get-DscConfigurationStatus

As this configuration is applied every 30 minutes frequency. in the next chapter I will show how to force a DSC Client to Refresh it's Configuration from the Pull Server.

Download this script here, This also available on Github.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#1: Run code on remote node to configuration Local configuration manager
Configuration SetLCMPullMode {
    param([string]$ComputerName,
        [guid]$Guid
    )
    
    Node $ComputerName {
        LocalConfigurationManager {
            ConfigurationID                    = $Guid
            DownloadManagerName                = 'WebDownloadManager'
            RefreshMode                        = 'Pull' 
            RebootNodeIfNeeded                 = $true
            RefreshFrequencyMins               = 30
            ConfigurationModeFrequencyMins     = 30
            ConfigurationMode                  = 'ApplyAndAutoCorrect'
            DownloadManagerCustomData = @{
                ServerUrl                      = 'http://dscserver:8080/PSDSCPullServer.svc/'
                AllowUnsecureConnection        = $true
            }
        }
    }
}

#2: Create the .mof file on remote node
cd C:\Temp
SetLCMPullMode -ComputerName srv01 -Guid 8b055a11-04fb-4eaf-b560-b5ea1fc3d298

#3: turn on pull mode on the remote node
Set-DscLocalConfigurationManager -Path .\SetLCMPullMode -Verbose

#4: Forcefully pull update dsc configuration and apply it, check the status
Update-DscConfiguration -Wait -Verbose
Get-DscConfigurationStatus

Useful Blogs
PART 1 : POWERSHELL - CREATE LOCAL IIS WEB REPOSITORY FOR DSC MODULE 
PART 2 : POWERSHELL - COPY DSC MODULE REMOTELY USING LOCAL WEB REPOSITORY
POWERSHELL CONVERT EXCEL TO DSC (DESIRED STATE CONFIGURATION) CONFIGURATION HASHTABLE FORMAT
Microsoft Powershell generate random anything (Filename, TempPath, GUID, Password)
THE POWERSHELL XACTIVEDIRECTORY PROVIDER DOES NOT EXIST AT THE POWERSHELL MODULE PATH NOR IS IT REGISTERED AS A WMI PROVIDER

Go Back

Comment

Blog Search

Page Views

12084965

Follow me on Blogarama