How to Set DSC LCM Meta Configuration Properties – part 2

This is second part of 10 series blog on LCM APIs and Internals. In last part, we saw “How to retrieve DCS LCM Meta Configuration Properties” using three different methods, namely WMI, CIM and DSC Cmdlet.

In this post, we will continue our journey and would see “How to Set DCS LCM Meta Configuration Properties” using the same three methods.

Using DSC Cmdlet

There is a special resource type named “LocalConfigurationManager” that should be used for the configuration of LCM properties. This resource type provides the same properties that we saw earlier post. These properties should be provided valid values to appropriate functioning of the LCM. Configuration scripts containing the “LocalConfigurationManager” resource type should not contain any other resource type.

MOF files should be generated from configuration files. We will generate the MOF file by executing the configuration. After the MOF file is generated instead of using Start-DSCConfiguration command, another cmdlet named Set-DSCLocalConfigurationManager is used to configure the target node’s meta configuration. Figure below depicts the configuration script and also the other steps for setting LCM metadata properties.

LCM-02-01

In above Image, We have a Configuration named SetLCMMetaConfiguration that would be applied on Local machine represented by “Localhost” as node name. The special resource type “LocalConfigurationManager” is used for configuring the LCM properties. Some of the properties of LCM has been assigned values. Only these properties would undergo change in their values. Rest of them would remain what their initial values are. We have changed values for AllowModuleOverwrite, ConfiguratinMode, RefreshModi and RefreshFrequencyMins.

We execute the Configuration script in the same script scope as configuration definition. As a result, a MOF file is generated at the location specified by the “OutputPath” attribute. After the MOF file is generated, Set-DscLocalConfigurationManager cmdlet is used to assign the configuration information to the target node’s LCM meta configuration properties. We have used the verbose switch for better understanding of underlying action taken by DSC.

Image below shows the output as the result of execution of the above script.

LCM-02-02

Note that in above image, a method called “SendMetaConfigurationApply” is invoked by LCM defined in class “MSFT_DSCLocalConfigurationManager” using Invoke-CIMMethod cmdlet.
As a result of execution of the script, the final LCM meta configuration changes and the new configuration is shown below. Note that the values we mentioned in Configuration script before are now reflected within properties of LCM meta configuration. Below, we can see that when we run Get-DSCLocalConfigurationManager on the same machine, the output reflects the new property values.

LCM-02-03

Using CIM and WMI

We are going to reuse the configuration script shown before and MOF file generated for setting up DSC LCM Meta Configuration properties using both CIM and WMI. However, with few changes. The new script is shown below.

LCM-02-04

We already saw that LCM is implemented within a class named MSFT_DSCLocalConfigurationManager”. This class has methods that implements the behavior of LCM. One of the method of this class is “SendMetaconfigurationApply”. It accepts a single argument named “Configurationdata” of type byte array. The method is responsible for updating and setting up the properties of the LCM meta configuration.

We also know that these MOF files are moved to target nodes and provided to target node’s LCM to configure itself. We will also send the content of the MOF file in a Byte array to LCM’s “SendMetaConfigurationApply” method. This method is invoked using “Invoke-CimMethod” cmdlet and passing single argument as a hashtable containing the MOF byte array. The result is shown below.

LCM-02-05

Here we have using CIM cmdlet. Similarly, use Invoke-wmimethod for using WMI.

Hope this post helps in more understanding DSC LCM.

Cheers!

Advertisements

3 thoughts on “How to Set DSC LCM Meta Configuration Properties – part 2

  1. Hi
    Congratulation for your articles. It is very interesting to see the three options for using DSC: DSC cmdlet, using cim and using wmi.
    I’m building a vmrole to customize a Windows 2008 R2 server, using DSC (I made it with 2012R2 ) and I find that in this system there is no update-dscconfiguration cmdlet to run the LCM without any delay.
    You know if I can run the LCM using cim or wmi? The VMRole can’t wait the minutes that the LCM takes to automatically start.
    Thank you very much
    Greetings
    Toni

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s