The LCM is a key component of DSC. LCM is a Windows service that runs on each DSC target node, and is responsible for receiving configuration information and ensuring that the node is configured in the desired state (and remains that way).
DSC has two mechanisms for the desired state delivery: push and pull. The earlier recipes in this chapter demonstrated the push model: you create a configuration and its related MOF file on one node and push that configuration to another node. In the pull model, you configure the node with details of where and how to find a pull server. Once configured, a node can pull configurations from the configured pull server. In both cases, it is the LCM that performs the actual configuration.
The way the LCM works changed in PowerShell version 5. In this recipe, which you run on SRV2
, you configure the LCM (based on the PowerShell V5 mechanism) on SRV2
and set up SRV2
to pull the DSC configuration from SRV1
which you set up as an SMB pull server. You set up SRV1
itself in the next recipe, Implementing an SMB pull server.
In this recipe, you use a special type of configuration known as a metaconfiguration. You use the metaconfiguration statement to configure DSC on a node. You run this recipe on the target node, SRV2
.
SRV2
and ensure that C:DSC
exists using the following code:$RIHT =@{ Path = 'C:WindowsSystem32configuration*.mof' ErrorAction = 'SilentlyContinue' } Get-Childitem @RIHT | Remove-Item @RIHT -Force $EASC = @{ ErrorAction = 'SilentlyContinue'} New-Item -Path c:DSC -ItemType Directory @EASC | Out-Null
Get-DscLocalConfigurationManager | Format-List -Property ActionafterReboot, AllowModuleOverwrite, Configuration*, LCMState, PartialConfigurations, Reboot*, Refresh*, Report*, Resource*
Configuration SRV2LcmConfig { Node Localhost{ LocalConfigurationManager { ConfigurationMode = 'ApplyOnly' RebootNodeIfNeeded = $true } } }
SRV2LcmConfig -OutputPath C:DSC
Set-DscLocalConfigurationManager -Path c:DSC -Verbose
Get-DscLocalConfigurationManager | Format-List -Property ActionafterReboot, AllowModuleOverwrite, Configuration*, LCMState, PartialConfigurations, Reboot*, Refresh*, Report*, Resource*
In step 1, you remove any existing DSC configuration MOF files for this node and ensure that the C:DSC
folder exists on SRV2
. There is no output from this step.
In step 2, you retrieve and view some of the properties of the DSC LCM on SRV2
, which looks like this:
In step 3, you create a configuration statement to configure the LCM of SRV2
. There is no output from this step.
In step 4, you execute the configuration to create the MOF file, which looks like this:
In step 5, you apply the LCM's configuration and, using the -Verbose
switch. You get the following output:
In the final step of this recipe, step 6, you review the key properties of the LCM of SRV2
, which looks like this:
18.118.0.248