An example LCM configuration

An example LCM configuration is as follows, saved as ExampleLCMConfig.ps1. We could have put this inside a regular DSC configuration file, but it was separated for a clearer example, as shown here:

    #Declare the configuration
Configuration SetTheLCM
{
# Declare the settings we want configured
LocalConfigurationManager
{
ConfigurationMode = "ApplyAndAutoCorrect"
ConfigurationModeFrequencyMins = 120
RefreshMode = "Push"
RebootNodeIfNeeded = $true
}
}

SetTheLCM

To compile this configuration into an MOF file, you execute the following configuration file in the PowerShell console:

    PS C:Examples> .ExampleLCMConfig.ps1

Directory: C:UsersJamesDesktopExamplesSetTheLCM

Mode LastWriteTime Length Name
--- ------------- ------ ----
-a--- 5/20/2015 7:28 PM 984 localhost.meta.mof

As we can see from the output, a localhost.meta.mof file was created inside a folder named for the configuration as a SetTheLCM folder. The filename reminds us again that the LCM settings are considered DSC metadata, so any files or operations on LCM get the meta moniker.

Looking at the contents of the MOF file, we see the same syntax as the MOF file generated by the DSC configuration file. We will keep seeing this standardized approach reused over and over again during our use of DSC, the importance of which we explained in Chapter 1, Introducing PowerShell DSC.

Let's take a look at the following snippet:

    /*
@TargetNode='localhost'
@GeneratedBy=James
@GenerationDate=05/20/2015 19:28:50
@GenerationHost=BLUEBOX
*/

instance of MSFT_DSCMetaConfiguration as $MSFT_DSCMetaConfiguration1ref
{
RefreshMode = "Push";
ConfigurationModeFrequencyMins = 120;
ConfigurationMode = "ApplyAndAutoCorrect";
RebootNodeIfNeeded = True;

};

instance of OMI_ConfigurationDocument
{
Version="1.0.0";
Author="James";
GenerationDate="05/20/2015 19:28:50";
GenerationHost="BLUEBOX";
};

We then execute the LCM configuration using the Set-DscLocalConfigurationManager cmdlet:

    PS C:Examples> Set-DscLocalConfigurationManager -Path .SetTheLCM -Verbose
VERBOSE: Performing the operation "Start-DscConfiguration: SendMetaConfigurationApply" on target
"MSFT_DSCLocalConfigurationManager".
VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' =
SendMetaConfigurationApply,'className' = MSFT_DSCLocalConfigurationManager,'namespaceName' =
root/Microsoft/Windows/DesiredStateConfiguration'.
VERBOSE: An LCM method call arrived from computer BLUEBOX with user sid *********************.
VERBOSE: [BLUEBOX]: LCM: [ Start Set ]
VERBOSE: [BLUEBOX]: LCM: [ Start Resource ] [MSFT_DSCMetaConfiguration]
VERBOSE: [BLUEBOX]: LCM: [ Start Set ] [MSFT_DSCMetaConfiguration]
VERBOSE: [BLUEBOX]: LCM: [ End Set ] [MSFT_DSCMetaConfiguration] in 0.0520 seconds.
VERBOSE: [BLUEBOX]: LCM: [ End Resource ] [MSFT_DSCMetaConfiguration]
VERBOSE: [BLUEBOX]: LCM: [ End Set ] in 0.2555 seconds.
VERBOSE: Operation 'Invoke CimMethod' complete.
VERBOSE: Set-DscLocalConfigurationManager finished in 0.235 seconds.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset