Our focus in this chapter is on how to push DSC configurations and not how to use DSC configurations, so our example configuration is simple and short. This reduces the amount of code we are working with and the amount of logging we output, which allows us to fit the DSC configurations in our chapter without having pages of printouts.
In our example script, we will create a text file on the primary drive with dummy contents. Again, we are purposely not being fancy here in order to focus on how to push DSC configurations and not the DSC configurations themselves:
Configuration SetupAllTheThings { Node "localhost" { File CreateFile { Ensure = "Present" DestinationPath = "c: est.txt" Contents = "Wakka" } } }
$mofPath = [IO.Path]::Combine($PSScriptRoot, "SetupAllTheThings") SetupAllTheThings -OutputPath $mofPath
Compiling the preceding DSC configuration script gives us a valid MOF file that we can use on the local computer. This should all be straightforward for you by now, and you should see the following results from the compiling of the MOF file:
[BOX1 PS] > C:vagrantSetupAllTheThings.ps1 Directory: C:vagrantSetupAllTheThings Mode LastWriteTime Length Name ---- ------------- ------ ---- ----- 7/01/2015 3:19 PM 1276 localhost.mof
If that doesn't compile correctly, look at your syntax and ensure it's the same as what we have laid out here. It may help if you add the Verbose parameter to our DSC configuration function to see what is going on as the MOF is compiled. If you are still having trouble or want to see even more information, then you can set your $DebugPreference to Continue and receive even more diagnostic information. An example output is as follows:
DEBUG: MSFT_PackageResource: ResourceID = [Package]InstallTheThing DEBUG: MSFT_PackageResource: Processing property 'DependsOn' [ DEBUG: MSFT_PackageResource: Processing completed 'DependsOn' ] DEBUG: MSFT_PackageResource: Processing property 'Ensure' [ DEBUG: MSFT_PackageResource: Processing completed 'Ensure' ] DEBUG: MSFT_PackageResource: Processing property 'Name' [ DEBUG: MSFT_PackageResource: Canonicalized property 'Name' = 'The Thing' DEBUG: MSFT_PackageResource: Processing completed 'Name' ] DEBUG: MSFT_PackageResource: Processing property 'Path' [ DEBUG: MSFT_PackageResource: Canonicalized property 'Path' = 'c:allthethings hing.msi' DEBUG: MSFT_PackageResource: Processing completed 'Path' ] DEBUG: MSFT_PackageResource: Processing property 'ProductId' [ DEBUG: MSFT_PackageResource: Canonicalized property 'ProductId' = '{8f665668-7679-4f53-acde-06cf7eab5d73}'
[BOX1 PS] > $error[0] | Format-List -Property * -Force
If we examine the localhost.mof file, we will see that the file resource laid out applies to a target node named localhost. This means that although we compile this MOF file on the computer we are sitting at, this MOF file can be pushed to any computer, whether locally or remotely, because localhost applies to any computer. If we wanted to restrict which target nodes used specific MOF files, we would need to specify their host names in the Node block. We will cover this when we deal with pushing DSC configurations remotely in a little bit.