Training
Module
Implement Desired State Configuration (DSC) - Training
Implement Desired State Configuration (DSC)
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
DSC Resources provide a standardized interface for managing the settings of a system. A resource defines properties you can manage and implements the code needed to get an instance of the resource.
Command-based DSC Resources are defined with at least two files:
DSC Resource manifests are defined as JSON files. For DSC to recognize a JSON file as a manifest, the file must meet the following criteria:
PATH
environment variable..dsc.resource.json
.When DSC searches the local system for available command-based DSC Resources, it searches every
folder in the PATH
for files that use the DSC Resource manifest naming convention. DSC then
parses each of those discovered files and validates them against the
DSC Resource Manifest JSON schema.
If the JSON file validates against the schema, DSC can use the DSC Resource.
At a minimum, the manifest must define:
Microsoft.Windows/Registry
. The fully qualified
name syntax is <owner>[.<group>][.<area>]/<name>
. The group and area components of the fully
qualified name enable organizing resources into namespaces.The manifest may optionally define:
If the manifest doesn't define how to test an instance of the resource, DSC performs a synthetic
test for resource instances. DSC's synthetic test always gets the actual state of an instance and
does a strict case-sensitive comparison of the instance's properties to the desired state. The
synthetic test ignores any properties prefixed with an underscore (_
) or dollar sign ($
). If
any of the properties aren't exactly the same as the defined desired state, DSC reports the
instance as being non-compliant.
If the manifest doesn't define how to set an instance of the DSC Resource, DSC can't use the resource to enforce desired state.
The manifest doesn't need to specify the same executable file for every operation. The definition for each operation is independent.
Command-based DSC Resources always require an executable file for DSC to run. The DSC Resource Manifest doesn't need to be bundled with the executable. The executable can be any executable file, such as a binary application or a shell script. A resource may use different executables for different operations.
For DSC to use an executable, it must be discoverable in the PATH
environment variable. DSC calls
the executable once per operation, using the exit code returned by the executable to determine if
the command was successful. DSC treats exit code 0
as a success and all other exit codes as an
error.
DSC sends input to command-based DSC Resources as either a JSON data blob over stdin or as a set of argument flags and values. Input handling is defined per-operation in the DSC Resource Manifest.
When DSC sends the input as JSON over stdin, the data blob is the JSON representation of an instance's desired state. This is the most robust option for a resource, as it enables the resource to support complex properties with nested objects.
When DSC sends the input as arguments, it generates a pair of arguments for each of the specified
properties. The first argument is the name of the property prefixed with --
, such as
--duration
. The second argument is the property's value. The ordering of the argument pairs isn't
guaranteed. This input method doesn't support complex properties.
The executable for a command-based DSC Resource must return JSON data to stdout when called by DSC. The output encoding must be UTF-8. When the resource returns the state of an instance, DSC validates the JSON data against the resource's instance schema.
For DSC Provider Resources, DSC expects the executable to pass through the instance states for the resources it manages as either a single JSON array or as a series of JSON Lines.
Command-based DSC Resources can report logging information to DSC by emitting JSON Lines to stderr. Each log entry must be a JSON object that includes two keys:
message
key defines the human-readable string for the log entry.level
key defines whether the message represents an Error
, a Warning
, or Information
.DSC collects messages from resources and displays them in the results for a configuration operation. When DSC invokes a resource directly outside of a configuration, it doesn't collect the messages. Instead, they're just emitted to stderr.
DSC feedback
DSC is an open source project. Select a link to provide feedback:
Training
Module
Implement Desired State Configuration (DSC) - Training
Implement Desired State Configuration (DSC)