Executing configurations for remote target nodes

Now that we have MOF files and CimSessions and are ready to start pushing DSC configurations to remote target nodes, we use Start-DSCConfiguration just like we did earlier, with the addition of using the CimSession parameter and passing the CimSession that we created previously to it.

Again, we use CimSession here because sometimes, you need special credentials, authentication, or other options in order to connect to remote target nodes. You can omit the creation of a separate CimSession here if you wish:

[BOX1 PS] > Start-DscConfiguration -Path C:vagrantSetupAllTheThings -Verbose -Wait -Force -CimSession $session
VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' =
SendConfigurationApply,'className' = MSFT_DSCLocalConfigurationManager,'namespaceName' =
root/Microsoft/Windows/DesiredStateConfiguration'.
VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' =
SendConfigurationApply,'className' = MSFT_DSCLocalConfigurationManager,'namespaceName' =
root/Microsoft/Windows/DesiredStateConfiguration'.
VERBOSE: An LCM method call arrived from computer BOX1 with user sid S-1-5-21-1953236517-242735908-2433092285-500.
VERBOSE: An LCM method call arrived from computer BOX1 with user sid S-1-5-21-1953236517-242735908-2433092285-500.
VERBOSE: [BOX2]: LCM: [ Start Set ]
VERBOSE: [BOX1]: LCM: [ Start Set ]
VERBOSE: [BOX2]: LCM: [ Start Resource ] [[File]CreateaFile]
VERBOSE: [BOX2]: LCM: [ Start Test ] [[File]CreateaFile]
VERBOSE: [BOX2]: [[File]CreateaFile] The system cannot find the file specified.
VERBOSE: [BOX2]: [[File]CreateaFile] The related file/directory is: c: est.txt.
VERBOSE: [BOX2]: LCM: [ End Test ] [[File]CreateaFile] in 0.0000 seconds.
VERBOSE: [BOX2]: LCM: [ Start Set ] [[File]CreateaFile]
VERBOSE: [BOX2]: [[File]CreateaFile] The system cannot find the file specified.
VERBOSE: [BOX2]: [[File]CreateaFile] The related file/directory is: c: est.txt.
VERBOSE: [BOX2]: LCM: [ End Set ] [[File]CreateaFile] in 0.0000 seconds.
VERBOSE: [BOX2]: LCM: [ End Resource ] [[File]CreateaFile]
VERBOSE: [BOX2]: LCM: [ End Set ]
VERBOSE: [BOX2]: LCM: [ End Set ] in 0.0000 seconds.
VERBOSE: Operation 'Invoke CimMethod' complete.
VERBOSE: [BOX1]: LCM: [ Start Resource ] [[File]CreateaFile]
VERBOSE: [BOX1]: LCM: [ Start Test ] [[File]CreateaFile]
VERBOSE: [BOX1]: [[File]CreateaFile] The destination object was found and no action is
required.
VERBOSE: [BOX1]: LCM: [ End Test ] [[File]CreateaFile] in 0.0160 seconds.
VERBOSE: [BOX1]: LCM: [ Skip Set ] [[File]CreateaFile]
VERBOSE: [BOX1]: LCM: [ End Resource ] [[File]CreateaFile]
VERBOSE: [BOX1]: LCM: [ End Set ]
VERBOSE: [BOX1]: LCM: [ End Set ] in 0.0630 seconds.
VERBOSE: Operation 'Invoke CimMethod' complete.
VERBOSE: Time taken for configuration job to complete is 0.086 seconds
[BOX1 PS] >

If all went well, you should see the preceding output on your test system. In the output, note that both box2 and box1 had DSC configurations applied to them. You can also see that we have more output for box2 than we have for box1. That is because the file was not present in box2, while it was present in box1. This is a great example of the benefit of CM products such as DSC; it detected that the file was already present in box1 and did not need to touch it while noticing that it was not present in box2 as well as creating it. Both actions were easily discovered in the log.

Also, note that we get the same format logging as we do when pushing DSC configurations locally even though we are operating on remote target nodes. Each log has the node that it is coming from, so it is easy to see which ones are for which hosts. This is useful for our Verbose messages but even more useful for any ErrorMessages that come from our executions. If we received an error during execution, it would look like this:

[BOX1 PS] > $error[0] | fl * -for
    
    writeErrorStream      : True
    PSMessageDetails      :
    OriginInfo            : REMOTE-TEST-COMPUTER
    Exception             : Microsoft.Management.Infrastructure.CimException: A configuration is
    ...
  

The OriginInfo property tells us which target node is sending us the error information. Of course, DSC logs all this information on the remote host, but it is very useful to receive it interactively as you test and develop your DSC configurations.

Something that we glossed over is that we pointed Start-DSCConfiguration to a folder containing more than one MOF file and it executed each MOF file on the respective target nodes with the correct credentials. How did it know that we needed to do that? This is a potentially powerful scenario.

Since Start-DSCConfiguration uses WinRM as the transport mechanism, it inherits all the power and flexibility of the command structures provided by WinRM. One of these is the ability to connect to many target nodes and execute a command at the same time. While we may have seen the output from box1 and box2 sequentially, the DSC execution jobs were performed in parallel or on both machines at once. The amount of work done in the DSC configuration file for each target node will determine how long the executions take on each node. Note that box2 finished earlier because it had less to do than box1. It only seemed like each target node was operated on sequentially because we used the Wait parameter, which indicated to Start-DSCConfiguration to only return control to the console session when all jobs had completed. You can imagine the usefulness when you can apply this to hundreds of machines at the same time.

..................Content has been hidden....................

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