The method of using Get-DscConfiguration to check whether the target node status works well if you have direct contact to the target nodes. If you provide multiple CimSessions to operate on, you can even get the status of many computers at one time. However, this doesn't work as well if you want to look at the historical logging of execution runs on target nodes.
DSC logging is the next step in how to get information on the status of DSC applying the DSC configurations. We can use the Get-xDscOperation function from the xDscDiagnostics module we covered earlier in the book in Chapter 3 Debugging and troubleshooting configuration script files section. We can use the output from AllEvents to see the logs of the executions that DSC performs. The default sort order shows the most recent first, so we will look at the second in the list to see the first operation DSC performed:
[PS]> (get-xdscoperation)[1].AllEvents | fl TimeCreated : 8/01/2015 4:17:52 PM Message : Configuration is sent from computer NULL by user sid S-1-5-18. EventType : OPERATIONAL TimeCreated : 8/01/2015 4:17:57 PM Message : Attempting to get the action from pull server using Download Manager WebDownloadManager. Configuration Id is 07f528b9-0f22-4029-a3a7-b836f8843d3d. Checksum is . Compliance status is false. EventType : OPERATIONAL TimeCreated : 8/01/2015 4:17:57 PM Message : WebDownloadManager for configuration 07f528b9-0f22-4029-a3a7-b836f8843d3d Do-DscAction command with server url: http://192.168.0.12:8080/PSDSCPullServer.svc. EventType : OPERATIONAL TimeCreated : 8/01/2015 4:17:57 PM Message : WebDownloadManager for configuration 07f528b9-0f22-4029-a3a7-b836f8843d3d Do-DscAction command, GET Url: PSDSCPullServer.svc/Action(ConfigurationId='07f528b9-0f22-4029-a3a7-b836f8843d3d')/GetAction. EventType : OPERATIONAL TimeCreated : 8/01/2015 4:17:59 PM Message : Successfully got the action GetConfiguration from pull server using Download Manager WebDownloadManager. EventType : OPERATIONAL TimeCreated : 8/01/2015 4:17:59 PM Message : WebDownloadManager for configuration 07f528b9-0f22-4029-a3a7-b836f8843d3d Do-DscAction command, GET call result: GetConfiguration. EventType : OPERATIONAL
So far, so good; we see that the target node contacted the DSC pull server and received instructions on what to do next. The target node will now attempt to pull the DSC configuration from the DSC pull server:
TimeCreated : 8/01/2015 4:17:59 PM Message : Attempting to get the configuration from pull server using Download Manager WebDownloadManager.Configuration Id is 07f528b9-0f22-4029-a3a7-b836f8843d3d. EventType : OPERATIONAL TimeCreated : 8/01/2015 4:17:59 PM Message : WebDownloadManager for configuration 07f528b9-0f22-4029-a3a7-b836f8843d3d Get-DscDocument command, GET Url: PSDSCPullServer.svc/Action(ConfigurationId='07f528b9-0f22-4029-a3a7-b836f8843d3d')/ConfigurationContent. EventType : OPERATIONAL TimeCreated : 8/01/2015 4:17:59 PM Message : WebDownloadManager for configuration 07f528b9-0f22-4029-a3a7-b836f8843d3d Get-DscDocument command, File save result: C:WindowsTEMP635756842794223943localhost.mof.checksum. EventType : OPERATIONAL TimeCreated : 8/01/2015 4:17:59 PM Message : The checksum validation for configuration C:WindowsTEMP\635756842794223943localhost.mof completed with status code 0. EventType : OPERATIONAL
These logs show that the target node successfully downloaded the DSC configuration (the MOF file) from the DSC pull server and verify that the checksum matched what the DSC pull server had:
TimeCreated : 8/01/2015 4:17:59 PM Message : Skipping pulling module PSDesiredStateConfiguration with version 1.0 as it already exists in this location C:Windowssystem32WindowsPowerShellv1.0ModulesPSDesiredStateConfigurationPSDesiredStateCon figuration.psd1. EventType : OPERATIONAL TimeCreated : 8/01/2015 4:17:59 PM Message : Attempting to get the modules from pull server using Download Manager WebDownloadManager. Configuration Id is 07f528b9-0f22-4029-a3a7-b836f8843d3d. Modules are (xWebAdministration,1.7.0.0). EventType : OPERATIONAL
Note that DSC determined that the PSDesiredStateConfiguration and xWebAdministration DSC resources were needed for this MOF file to be executed, so it checked the target node for their presence. It found that the version of PSDesiredStateConfiguration present on the target node matched the version specified in the MOF file, so it did not have to download a new one, but the xWebAdministration DSC resource was not present at all, so it needed to download it:
TimeCreated : 8/01/2015 4:17:59 PM Message : WebDownloadManager Get-DscModule command, module xWebAdministration, GET Url: PSDSCPullServer.svc/Module( ConfigurationId='07f528b9-0f22-4029-a3a7-b836f8843d3d',ModuleName='xWebAdministration',ModuleVersion='1.7 .0.0')/ModuleContent. EventType : OPERATIONAL TimeCreated : 8/01/2015 4:17:59 PM Message : Attempting to get the modules {(xWebAdministration,1.7.0.0)} from pull server with Server Url http://192.168.0.12:8080/PSDSCPullServer.svc using Web Download Manager. EventType : OPERATIONAL TimeCreated : 8/01/2015 4:17:59 PM Message : WebDownloadManager Get-DscModule command, module xWebAdministration, File save result: C:WindowsTEMP635756842794223943xWebAdministration_1.7.0.0.zip.checksum. EventType : OPERATIONAL TimeCreated : 8/01/2015 4:17:59 PM Message : WebDownloadManager Get-DscModule command, module xWebAdministration, File save result: C:WindowsTEMP635756842794223943xWebAdministration_1.7.0.0.zip. EventType : OPERATIONAL TimeCreated : 8/01/2015 4:17:59 PM Message : The modules (xWebAdministration,1.7.0.0) were downloaded to the location C:WindowsTEMP\635756842794223943. EventType : OPERATIONAL TimeCreated : 8/01/2015 4:17:59 PM Message : The checksum validation for module xWebAdministration completed with status code 0. EventType : OPERATIONAL TimeCreated : 8/01/2015 4:18:00 PM Message : Successfully got the modules from pull server using Download Manager WebDownloadManager. EventType : OPERATIONAL TimeCreated : 8/01/2015 4:18:00 PM Message : The content validation for module xWebAdministration completed with status code 0. EventType : OPERATIONAL TimeCreated : 8/01/2015 4:18:00 PM Message : The modules xWebAdministration were installed at the location C:Program FilesWindowsPowerShellModulesxWebAdministration. EventType : OPERATIONAL
DSC successfully downloaded any DSC resources that were needed and verified that the downloaded files matched the checksum stored in the DSC pull server, all without any action on our part. This is much easier than pushing DSC configurations around.
Now that DSC has the correct DSC resources residing on the target node, it asks for the next step to perform. We'll look at the first record for the logs from that execution:
[PS]> (get-xdscoperation)[0].AllEvents | fl TimeCreated : 8/01/2015 4:27:59 PM Message : WebDownloadManager for configuration 07f528b9-0f22-4029-a3a7-b836f8843d3d Do-DscAction command with server url: http://192.168.0.12:8080/PSDSCPullServer.svc. EventType : OPERATIONAL TimeCreated : 8/01/2015 4:27:59 PM Message : Attempting to get the action from pull server using Download Manager WebDownloadManager. Configuration Id is 07f528b9-0f22-4029-a3a7-b836f8843d3d. Checksum is 0A6066B1398ABBEBA442775512E60E5392C3873F3F13C9E5B1E80B3C3FC681A4. Compliance status is true. EventType : OPERATIONAL
DSC checks to see whether the MOF file resident on the target node is the same as the one on the DSC pull server before it continues to make sure things have not changed since the last time. It then issues a call to see what the next action is, which is to apply the MOF file to the target node:
TimeCreated : 8/01/2015 4:27:59 PM Message : Configuration is sent from computer NULL by user sid S-1-5-18. EventType : OPERATIONAL TimeCreated : 8/01/2015 4:27:59 PM Message : WebDownloadManager for configuration 07f528b9-0f22-4029-a3a7-b836f8843d3d Do-DscAction command, GET Url: PSDSCPullServer.svc/Action(ConfigurationId='07f528b9-0f22-4029-a3a7-b836f8843d3d')/GetAction. EventType : OPERATIONAL TimeCreated : 8/01/2015 4:27:59 PM Message : WebDownloadManager for configuration 07f528b9-0f22-4029-a3a7-b836f8843d3d Do-DscAction command, GET call result: Ok. EventType : OPERATIONAL TimeCreated : 8/01/2015 4:27:59 PM Message : Running consistency engine. EventType : OPERATIONAL TimeCreated : 8/01/2015 4:27:59 PM Message : Successfully got the action Ok from pull server using Download Manager WebDownloadManager. EventType : OPERATIONAL TimeCreated : 8/01/2015 4:28:04 PM Message : Consistency engine was run successfully. EventType : OPERATIONAL
The last several events show that DSC applies the MOF file to the target node and reports success as a result. If we wait until the next DSC consistency check, we can see DSC determine whether the system is still in the desired state. We use the first record because this is now the most recent event in the system:
[PS]> (get-xdscoperation)[0].AllEvents | fl TimeCreated : 8/01/2015 4:42:11 PM Message : Configuration is sent from computer NULL by user sid S-1-5-18. EventType : OPERATIONAL TimeCreated : 8/01/2015 4:42:11 PM Message : Attempting to get the action from pull server using Download Manager WebDownloadManager. Configuration Id is 07f528b9-0f22-4029-a3a7-b836f8843d3d. Checksum is 0A6066B1398ABBEBA442775512E60E5392C3873F3F13C9E5B1E80B3C3FC681A4. Compliance status is true. EventType : OPERATIONAL