This is the second part of the series Desired State Configuration.
In this post we will look into some of the internal details about the configuration we created in the previous post.
In the last post, we talked about the some of the fundamentals of desired state configuration. We talked about what DSC is all about and a sample DSC script and the way Powershell has been extended to include the capabilities of DSC.
DSC is semantically equal to a Powershell function not only in terms of invoking it but it is also treated as a function. To prove it run the following command with Powershell ISE. Here “EnableFeatures” is the name of the configuration created in the earlier blog post
Within the output from the above command, look for the key called PSDrive, PSPath and PSProvider.
The values for all the above three keys reflect that the created configuration called “EnableFeatures” reflect that indeed the configuration is nothing more than a function.
Also, if you change the drive and change it to function drive, the configuration “EnableFeatures” would be visible within the list of functions. To prove type the following command within Powershell ISE.
The prompt would change to
Type Dir in Powershell ISE.
Within the result, “EnableFeatures” would be available within the list of functions obviously with commandtype of type “Configuration”.
Now, let’s focus towards MOF files that are generated when the Configuration is invoked. We will look into details about how to invoke the configuration in future post but in short invoking a configuration with Powershell ISE is nothing more than dot-sourcing the configuration file and calling the configuration by name.
Management Object Format (MOF) files are generated when Configuration is invoked.
A MOF file is generated for each Node within the configuration file.
We have saved the Configuration as Test.ps1 at C:\
We will then dot-source the powershell script such that “EnableFeatures” configuration is available in the global scope.
Once the script and its artifacts are loaded, “EnableFeatures” configuration should be invoked.
And the following is the output.
In the above image, there are few important information provided like
A directory created with the name of the configuration called “EnableFeatures” within the user’s local directory.
Within this directory 2 MOF are generates one for each target server. In this the example they are “WIN-PETR4TD7LAA” and “SCR2i”.
The .mof files looks like below.
The important thing to note here is that the information is collected from the Configuration file and this MOF file is created. This MOF file is needed for pushing the configuration information to the target server.
Powershell adds a new Command type called Configuration to differentiate between function and Configuration. When you run the above Get-command command, there is another key-value pair called CommandType available as output which reflects that it is of type “Configuration”.
In next post, we will look into end to end process of executing a DSC configuration file.
Hope you are finding these posts useful.