@@ -3,46 +3,47 @@ description: >-
33 DSC configuration documents are YAML or JSON data files that define the desired state of a system
44 declaratively. They are used to retrieve, validate, and enforce the state of multiple resource
55 instances.
6- ms.date : 08/07/2023
7- title : DSC Configuration Documents
6+ ms.date : 03/04/2025
7+ title : DSC configuration documents
88---
99
10- # DSC Configuration Documents
10+ # DSC configuration documents
1111
1212<!-- markdownlint-disable MD013 -->
1313
1414In Microsoft's Desired State Configuration (DSC) platform, DSC configuration documents declare the
1515desired state of a system as data files. Configuration documents define a collection of
16- [ DSC Resource] [ 01 ] instances to describe what the desired state should be, not how to put the
17- system into that state. The DSC Resources handle the _ how_ for the configuration document
18- instances.
16+ [ DSC resource] [ 01 ] instances to describe what the desired state should be, not how to put the
17+ system into that state. The DSC resources handle the _ how_ for each instance.
1918
20- DSCv3 can process configuration documents to:
19+ DSC can process configuration documents to:
2120
2221- Retrieve the current state of the defined resource instances with the ` dsc config get ` command.
2322- Validate whether the instances are in the desired state with the ` dsc config test ` command.
2423- Enforce the desired state for the instances with the ` dsc config set ` command.
24+ - Export a new configuration document with every instance of a set of resources with the
25+ ` dsc config export ` command.
2526
2627Configuration documents are YAML or JSON files that contain a single object. The object's
27- properties define how DSCv3 processes the document. The top-level properties for a document are:
28+ properties define how DSC processes the document. The top-level properties for a document are:
2829
29- - ` $schema ` (required) - Defines the canonical URI for the JSON Schema the document adheres to. DSC
30+ - ` $schema ` (required) - Defines the URI for the JSON Schema the document adheres to. DSC
3031 uses this to know how to validate and interpret the document.
3132- ` resources ` (required) - Defines the collection of resource instances the document manages.
32- - ` metadata ` (optional) - Defines an arbitrary set of annotations for the document. DSC doesn't
33- validate this data or use it directly. The annotations can include notes like who authored the
34- document, the last time someone updated it, or any other information. DSC doesn't use the
35- annotations. The metadata is for documentation or other tools to use.
33+ - ` metadata ` (optional) - Defines an arbitrary set of annotations for the document. Except for
34+ metadata within the ` Microsoft.DSC ` property, DSC doesn't validate this data or use it directly.
35+ The annotations can include notes like who authored the document, the last time someone updated
36+ it, or any other information. DSC doesn't use the annotations. The metadata is for documentation
37+ or other tools to use.
38+
39+ DSC applies validation to the ` Microsoft.DSC ` property. For more information, see the
40+ [ DSC Configuration document metadata schema] [ 02 ] reference.
3641- ` parameters ` (optional) - Defines a set of runtime options for the configuration. Parameters can
3742 be referenced by resource instances to reduce duplicate definitions or enable dynamic values.
3843 Parameters can have default values and can be set on any configuration operation.
3944- ` variables ` (optional) - Defines a set of reusable values for the configuration. Variables can be
4045 referenced by resource instances to reduce duplicate definitions.
4146
42- > [ !NOTE]
43- > DSC isn't implemented to process the ` parameters ` and ` variables ` properties yet. They can be
44- > defined in a document, but not referenced.
45-
4647## Defining a configuration document
4748
4849Minimally, a configuration document defines the ` $schema ` and ` resources ` properties. The
@@ -53,7 +54,7 @@ For example:
5354
5455``` yaml
5556# example.dsc.config.yaml
56- $schema : https://raw.githubusercontent.com/PowerShell/DSC/main/ schemas/2023/08 /config/document.json
57+ $schema : https://aka.ms/dsc/ schemas/v3/bundled /config/document.json
5758resources :
5859 - name : example key value
5960 type : Microsoft.Windows/Registry
@@ -64,7 +65,7 @@ resources:
6465 String : This is an example.
6566` ` `
6667
67- The example document defines a single resource instance called ` example key value`. The instance
68+ The example document defines a single resource instance named ` example key value`. The instance
6869uses the `Microsoft.Windows/Registry` resource to declare the following desired state :
6970
7071- The `example\key` registry key should exist in the system's current user hive.
@@ -75,17 +76,21 @@ The example document is _declarative_. It describes the desired state, not how t
7576into that state. It relies on the `Microsoft.Windows/Registry` resource to handle getting, testing,
7677and setting the state of the registry key and value.
7778
79+ For more information about the structure and validation of configuration documents, see
80+ [DSC Configuration document schema reference][03].
81+
7882# ## Defining resource instances
7983
8084As shown in the prior example, configuration documents include a collection of resource instances.
81- Together, the instances describe the desired state of a system. A configuration document can include any
82- number of resource instances.
85+ Together, the instances describe the desired state of a system. A configuration document can
86+ include any number of resource instances.
8387
8488A resource instance declaration always includes :
8589
8690- ` name` - A short, human-readable name for the instance that's unique in the document. This name
8791 is used for logging and it helps describe the purpose of the instance.
88- - ` type` - The [fully qualified type name][02] of the resource that DSC should use to manage the instance.
92+ - ` type` - The [fully qualified type name][04] of the resource that DSC should use to manage the
93+ instance.
8994- ` properties` - The desired state for the instance. DSC validates the values against the
9095 resource's instance schema.
9196
@@ -96,60 +101,86 @@ incompatible state for the instance on every run.
96101# # Getting the current state of a configuration
97102
98103The `dsc config get` command retrieves the current state of the resource instances defined in a
99- configuration document. DSC also collects any message emitted by the resources during the operation
100- and indicates whether any of the resources raised an error.
104+ configuration document. DSC also collects any message emitted by the resources during the
105+ operation, indicates whether any of the resources raised an error, and provides metadata about the
106+ operation as a whole and for each resource instance.
101107
102108` ` ` sh
103- cat ./example.config.dsc.yaml | dsc config get
109+ dsc config get --file ./example.config.dsc.yaml
104110` ` `
105111
106112` ` ` yaml
113+ metadata:
114+ Microsoft.DSC:
115+ version: 3.0.0
116+ operation: get
117+ executionType: actual
118+ startDatetime: 2025-02-24T16:09:40.671454400-06:00
119+ endDatetime: 2025-02-24T16:09:41.850086300-06:00
120+ duration: PT1.1786319S
121+ securityContext: restricted
107122results:
108- - name: example key value
123+ - metadata:
124+ Microsoft.DSC:
125+ duration: PT0.2751153S
126+ name: example key value
109127 type: Microsoft.Windows/Registry
110128 result:
111129 actualState:
112- $id: https://developer.microsoft.com/json-schemas/windows/registry/20230303/Microsoft.Windows.Registry.schema.json
113- keyPath: ''
130+ keyPath: HKCU \e xample \k ey
131+ _exist: false
114132messages: []
115133hadErrors: false
116134` ` `
117135
118136# # Testing a configuration
119137
120- The `dsc config test` command compares the current state of the resource instances to their desired state. The result for each instance includes :
138+ The `dsc config test` command compares the current state of the resource instances to their desired
139+ state. The result for each instance includes :
121140
122141- The desired state for the instance.
123142- The actual state of the instance.
124143- Whether the instance is in the desired state.
125144- The list of properties that are out of the desired state, if any.
126145
127- DSC also collects any message emitted by the resources during the operation and indicates whether
128- any of the resources raised an error.
146+ DSC also collects any message emitted by the resources during the operation, indicates whether any
147+ of the resources raised an error, and provides metadata about the operation as a whole and for each
148+ resource instance.
129149
130150` ` ` sh
131- cat . /example.config.dsc.yaml | dsc config test
151+ dsc config test --file /example.config.dsc.yaml
132152` ` `
133153
134154` ` ` yaml
155+ metadata:
156+ Microsoft.DSC:
157+ version: 3.0.0
158+ operation: test
159+ executionType: actual
160+ startDatetime: 2025-02-24T16:11:42.798122500-06:00
161+ endDatetime: 2025-02-24T16:11:43.442216400-06:00
162+ duration: PT0.6440939S
163+ securityContext: restricted
135164results:
136- - name: example key value
165+ - metadata:
166+ Microsoft.DSC:
167+ duration: PT0.2234078S
168+ name: example key value
137169 type: Microsoft.Windows/Registry
138170 result:
139171 desiredState:
140- valueData:
141- String: This is an example.
142172 keyPath: HKCU\e xample\k ey
143173 valueName: Example
174+ valueData:
175+ String: This is an example.
144176 actualState:
145- $id: https://developer.microsoft.com/json-schemas/windows/registry/20230303/Microsoft.Windows.Registry.schema.json
146- keyPath: ''
147- _inDesiredState: false
177+ keyPath: HKCU\e xample\k ey
178+ _exist: false
148179 inDesiredState: false
149180 differingProperties:
150- - valueData
151- - keyPath
152181 - valueName
182+ - valueData
183+ - _exist
153184messages: []
154185hadErrors: false
155186` ` `
@@ -163,42 +194,56 @@ their desired state. The result for each instance includes:
163194- The state of the instance after the operation.
164195- Which properties the operation changed, if any.
165196
166- DSC also collects any message emitted by the resources during the operation and indicates whether
167- any of the resources raised an error.
197+ DSC also collects any message emitted by the resources during the operation, indicates whether any
198+ of the resources raised an error, and provides metadata about the operation as a whole and for each
199+ resource instance.
168200
169201` ` ` sh
170- cat ./example.config.dsc.yaml | dsc config set
202+ dsc config set --file ./example.config.dsc.yaml
171203` ` `
172204
173205` ` ` yaml
206+ metadata:
207+ Microsoft.DSC:
208+ version: 3.0.0
209+ operation: set
210+ executionType: actual
211+ startDatetime: 2025-02-24T16:13:32.746742600-06:00
212+ endDatetime: 2025-02-24T16:13:33.606785-06:00
213+ duration: PT0.8600424S
214+ securityContext: restricted
174215results:
175- - name: example key value
216+ - metadata:
217+ Microsoft.DSC:
218+ duration: PT0.4070001S
219+ name: example key value
176220 type: Microsoft.Windows/Registry
177221 result:
178222 beforeState:
179- $id: https://developer.microsoft.com/json-schemas/windows/registry/20230303/Microsoft.Windows.Registry.schema.json
180- keyPath: ''
223+ keyPath: HKCU \e xample \k ey
224+ _exist: false
181225 afterState:
182- $id: https://developer.microsoft.com/json-schemas/windows/registry/20230303/Microsoft.Windows.Registry.schema.json
183226 keyPath: HKCU\e xample\k ey
184227 valueName: Example
185228 valueData:
186229 String: This is an example.
187230 changedProperties:
188- - keyPath
189231 - valueName
190232 - valueData
233+ - _exist
191234messages: []
192235hadErrors: false
193236` ` `
194237
195238# # See also
196239
197240- [DSC Resources][01] to learn about resources.
198- - [DSC Configuration document schema reference][03 ]
199- - [Command line reference for the 'dsc config' command][04 ]
241+ - [DSC Configuration document schema reference][05 ]
242+ - [Command line reference for the 'dsc config' command][06 ]
200243
201244[01] : ./resources.md
202- [02] : ./resources .md#resource-type-names
245+ [02] : ../reference/schemas/config/metadata .md#microsoftdsc
203246[03] : ../reference/schemas/config/document.md
204- [04] : ../reference/cli/config/command.md
247+ [04] : ./resources.md#resource-type-names
248+ [05] : ../reference/schemas/config/document.md
249+ [06] : ../reference/cli/config/command.md
0 commit comments