You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 15, 2026. It is now read-only.
By now, you should have run at least one command using `dsc`. The output displayed in the CLI might look different from what you're used to, especially if you're familiar with previous versions. The output format is YAML (Yet Another Markup Language), chosen by the team primarily for its readability. There is however a transformation happening when the engine handles the input and output. Take for example the following command to output the results to a file:
14
+
By now, you learned how to run commands using `dsc`. The output format returned to the console was YAML (Yet Another Markup Language), chosen by the team for its readability. Compared to previous versions, mainly PowerShell objects are returned to the console.
15
+
16
+
There is however a transformation happening when the engine handles the input and output. Take for example the following command to output the results to a file:
When output is redirected in your shell, such as to a file in this example, the data is formatted in JSON. By default, the engine uses JSON for both input and output unless a different format is explicitly specified. That's why in this next step further, you will learn:
26
+
When output is _redirected_ or _piped_in the shell, the data format is JSON. By default, the engine's input and output is JSON, unless specified otherwise. That's why in this next step of the template, you'll learn:
25
27
26
28
- Understanding input formats in DSC
27
29
- Exploring output transformations
28
30
- The DSC Resource Manifest
29
31
30
32
## Understanding Input Formats in DSC
31
33
32
-
Let's take a step back and use the `dsc resource` command to explore the input and output in a safe manner without affecting your system. For that, you can leverage the `Microsoft.DSC.Debug/Echo` resource. This resource _echos_ back what you've entered. Before doing so, let's look at an earlier example.
34
+
Let's take a step back and use the `dsc resource` command to explore the input and output in a safe manner without affecting your system. For that, you can leverage the `Microsoft.DSC.Debug/Echo` resource. This resource _echos_ back what you've entered to the console application your working in. Let's grab the example from earlier exercises.
33
35
34
-
As mentioned, the primary driver for the engine is JSON. Remember when you entered the temple, there was the following example:
36
+
DSC's engine primary driver is JSON. Make note of that. Now, take a look at the exercise done earlier:
This example demonstrates how you can use PowerShell to process the output returned by the CLI. PowerShell provides commands that make it easy to transform CLI output into PowerShell objects. For instance, you can see the `ConvertFrom-Json` command to convert JSON output, and then filter and select specific properties using `Where-Object` and `Select-Object`.
45
+
This example demonstrates how you can use PowerShell to process the output returned by the CLI. PowerShell provides commands that make it easy to transform CLI output into PowerShell objects. For instance, you can see the `ConvertFrom-Json` command to convert JSON output, and then filter and select specific properties using `Where-Object` and `Select-Object` commands.
46
+
47
+
PowerShell isn't limited to Windows anymore. It can run on MacOS and Linux, but you don't have to use it. Instead, there are other tools for parsing, filtering, and modifying JSON by using for example [jq](https://jqlang.org/).
44
48
45
-
Whilst PowerShell runs both on MacOS and Linux, you can use other widely used tools for parsing, filtering, and modifying JSON by using for example [jq](https://jqlang.org/). For this section, PowerShell is used, but know there are other possibilities.
49
+
> [!TIP]
50
+
> Know that these tools are available on the market and you're not limited in using PowerShell.
46
51
47
52
Time to examine the possibilities to input the required properties by executing the `Microsoft.DSC.Debug/Echo` resource. First, run the following command: `dsc resource schema --resource Microsoft.DSC.Debug/Echo` to indicate what input is required.
dsc resource get --resource Microsoft.DSC.Debug/Echo --file $outFile
107
112
```
108
113
109
-
You have multiple input formats in DSC, including the possible options to sent it towards the DSC resource if it_requires it_. Let's take a look at the output transformations.
114
+
You have now learned about the multiple input formats DSC can use. You've seen the possible options by either using `--input` or `--file` if the DSC resource requires it. In the next section, you are going to learn about the output transformations.
110
115
111
116
## Explore Output Transformations in DSC
112
117
@@ -154,7 +159,7 @@ By specifying the `--output-format` option, you can control how the CLI formats
154
159
155
160
## The DSC Resource Manifest
156
161
157
-
Without the DSC resource manifest, DSC will be a blank check. Remember when you started about these file suffixes? This is the resource manifest. The resource manifest is the critical component, which provides metadata about a _resource_. To see it in a simplistic way, you can output the resource manifest of the `Microsoft.Windows/Registry` resource by running:
162
+
Without the DSC resource manifest, DSC will be a blank check. In level 1, you learned the steps what happens in the background when calling `dsc resource list`. These file suffixes are the resource manifest it attempted to look for. The resource manifest is the critical component, which provides metadata about a _resource_. To see it in a simplistic way, you can output the resource manifest of the `Microsoft.Windows/Registry` resource by running:
158
163
159
164
```powershell
160
165
dsc resource list --description "Manage Windows Registry keys and values" |
@@ -182,7 +187,7 @@ What you see here, is the following:
182
187
183
188
1. The executable that will be called: `registry`
184
189
2. The arguments that are passed along: `config get`
185
-
3. The input option that is mandatory: `--input`
190
+
3. The input argument that is mandatory: `--input`
186
191
187
192
To make this example a little bit more clearer, you can literally run the `registry` executable using the following command:
> Wondering how you can get the input for the executable? Run `registry schema` or `dsc resource schema --resource Microsoft.Windows/Registry` to see the required and optional input.
195
200
196
-
DSC wraps itself around the executable and calls it underneath. The same example can be called using `dsc` as followed:
201
+
DSC wraps itself around the executable and calls it by spawning it as a _child process_. The same example can be called using `dsc` as followed:
197
202
198
203
```sh
199
204
dsc resource get --resource Microsoft.Windows/Registry --input 'keyPath: HKCU'
@@ -207,18 +212,18 @@ If you put on the tracing level to `trace`, you can spot what DSC does:
Let's digest it further by looking to the key elements.
215
+
Let's look at some key elements in more depth.
211
216
212
217
### Key Elements of the Manifest
213
218
214
-
You have seen now at least one element of the resource manifest which is important. The `capabilities` element defines the executables capabilities. In the `Microsoft.Windows/Registry`, there are four capabilities:
219
+
You have seen now at least one element of the resource manifest which is important. The `capabilities` element defines the executables capabilities. In the `Microsoft.Windows/Registry` resource manifest, there are four capabilities specified:
215
220
216
221
-`get`
217
222
-`set`
218
223
-`whatIf`
219
224
-`delete`
220
225
221
-
Each DSC resource should specify the `type` property to define its purpose based on the fully qualified name syntax. This follows the following syntax: `<owner>[.<group>][.<area>]/<name>` allowing organizations to group resources into namespaces. Additionally, the `kind` property provides further context telling what the resource is about. The `Microsoft.Windows/Registry` is of kind `resource`.
226
+
Each DSC resource should specify the `type` property to define its purpose based on the fully qualified name syntax. This follows the following syntax: `<owner>[.<group>][.<area>]/<name>` allowing organizations to group resources into namespaces. Additionally, the `kind` property provides further context telling what the resource is about. The `Microsoft.Windows/Registry` is of kind `resource`, indication it is a command-based DSC resource.
The resource manifest is the backbone of how DSC interacts with resources. That's why understanding and absorbing the resource manifest in your knowledge database (brain), helps you understand the other schematics more effortlessly. Hence, this chapter is dedicated to dive deeper into the resource manifest on a step-by-step basis.
14
+
The resource manifest is the backbone of how DSC interacts with resources. That's why understanding and absorbing the resource manifest in your brain, helps you understand the other schematics more effortlessly. Hence, this chapter is dedicated to dive deeper into the resource manifest on a step-by-step basis.
15
15
16
-
Brace yourself for it in this part of the temple, as you're going to absorb the resource manifest like a sponge does with all the water, by learning the following topics:
16
+
Brace yourself young initiate. You are going to absorb the resource manifest like a sponge does with all the water. You will go through the following topics:
17
17
18
18
- The schema URI
19
19
- List of different capabilities
@@ -28,7 +28,7 @@ When you inspect the schema of the resource manifest using the `dsc schema --typ
28
28
29
29
In this case, the enumeration includes two versions of URLs. One of these URLs uses Microsoft's `aka.ms` URL shortener, which simplifies the URL for easier recall. However, the short URL ultimately redirects to the actual schema location.
30
30
31
-
Taking by example, let's use the following URL: `https://aka.ms/dsc/schemas/v3/bundled/resource/manifest.json`. This URL redirects to the actual schema file hosted at: `https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/v3/bundled/resource/manifest.json`.
31
+
Taking by example, the following URL: `https://aka.ms/dsc/schemas/v3/bundled/resource/manifest.json` redirects to the actual schema file hosted at: `https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/v3/bundled/resource/manifest.json`.
32
32
33
33
{{< figure
34
34
src="/images/resource-manifest-schema-uri.png"
@@ -102,7 +102,7 @@ The `manifest.vscode.json` versions differ slightly as they are specifically des
102
102
caption="Figure 2: Visual Studio Code enhanced authoring"
103
103
>}}
104
104
105
-
Most importantly to remember, is the schema will evolve over time. New versions may be introduced that differ from the version used in your CLI. Whenever your authoring a resource manifest, always use the latest schema version available. For a full list of schemas, you can go to: <https://github.com/PowerShell/DSC/tree/main/schemas>
105
+
Schemas evolve over time. New versions may be introduced that differ from the version used in your CLI. Whenever your authoring a resource manifest, always use the latest schema version available. For a full list of schemas, you can go to: <https://github.com/PowerShell/DSC/tree/main/schemas>
106
106
107
107
## List of Different Capabilities
108
108
@@ -119,7 +119,7 @@ Let's look closely to each of the capabilities
119
119
120
120
### Get
121
121
122
-
You have already used this capability when you called the DSC resource `Microsoft/OSInfo` or `Microsoft.Windows/Registry`. It gets the current state of the DSC resource. Capability is often referred to as _method_ and this can be seen in the resource manifest:
122
+
You have already used this capability when you called the DSC resource `Microsoft/OSInfo` or `Microsoft.Windows/Registry`. It gets the current state of the DSC resource. Capability is often referred to as _method_ and this is visible in the resource manifest.
123
123
124
124
```yaml
125
125
GetMethod:
@@ -144,7 +144,7 @@ GetMethod:
144
144
- type: 'null'
145
145
```
146
146
147
-
You have already digested some of the parts on the get capability, but the resource manifest reveals the information. The `executable` propertyis always mandatory. It should be of type `string`. Then, looking at the definition of `ArgKind`, the following properties are available:
147
+
You've seen the first part of the `get` capability. The resource manifest reveals more information, such as the `executable` property, which is mandatory and should be of type `string`. Looking further at the definition `ArgKind`, the following properties are available:
148
148
149
149
```yaml
150
150
ArgKind:
@@ -166,9 +166,9 @@ ArgKind:
166
166
- 'null'
167
167
```
168
168
169
-
When defining the `args` object in your resource manifest, the `anyOf` keyword allows for two flexible options. You can either provide a straightforward string as the argument or define a more complex object. This object must include the `jsonInputArg` property, which specifies the argument that accepts the JSON input object or string. Additionally, you can use the `mandatory` property to indicate whether the argument is required.
169
+
When defining the `args` object in your resource manifest, the `anyOf` keyword allows for two flexible options. You can either provide a straightforward string as the argument or define a more complex object. This object must include the `jsonInputArg` property, specifying the argument which accepts a JSON input object or string. You can add the `mandatory` property to indicate if input is required or not.
170
170
171
-
To understand the concept more and link the schema towards a DSC resource, you can take a look at the `Microsoft.Windows/Registry` resource, which perfectly illustrates it in the following snippet:
171
+
To understand the concept more and link the schema against a DSC resource, you can take a look at the `Microsoft.Windows/Registry` resource. The following snippet illustrates the properties in the current resource manifest:
172
172
173
173
```json
174
174
"get": {
@@ -199,7 +199,7 @@ InputKind:
199
199
- stdin
200
200
```
201
201
202
-
Most CLIs pass a JSON object through STDIN. STDIN stands for standard input and is commonly used in command-line interfaces representing the input stream which a program reads data from. In this case, DSC sends that data to the executable. Alternatively, the input can also be set as environment variable.
202
+
Most CLIs pass a JSON object through STDIN. STDIN stands for standard input and is commonly used in command-line interfaces representing the input stream which a program reads data from. In this case, DSC sends data to the executable. Alternatively, the input can also be set as environment variable.
203
203
204
204
### Set
205
205
@@ -275,12 +275,86 @@ For example, in the `Microsoft.Windows/Registry` resource, the `Set` capability
275
275
276
276
In the `SetMethod`, there are two properties added. The `implementsPretest` property in the resource manifest indicates whether the resource performs its own validation. In this case, it will call the `Test` method itself if it has been set to `True`. In the `Microsoft.Windows/Registry` it hasn't been set. However, if it was set to `True`, you can imagine that the resource itself would require to call the `Test` method when you want to set a `keyPath` even it was already present.
277
277
278
-
The `handlesExist` property has been added to the resource manifest and stems of from previous DSC versions. If a resource in itself handles the `_exist` property, you can turn on this flag to `True`. This concept is more advanced and will be later handled.
278
+
The last property `handlesExist` is newly added to the resource manifest. It helps indicating to `dsc` if the `_exist` propertycan be used in `set` operations for creating or deleting instances. This concept is more advanced and will be touch upon later.
279
279
280
280
By defining the `Set` capability in this way, the resource manifest ensures that the resource can be configured to match the desired state.
281
281
282
282
### Test
283
283
284
+
The `Test` capability tests the state of the resource. Imagine you wanna know if the `HKLM\CustomPath` has been added correctly added. Invoking `dsc resource test --resource Microsoft.Windows/Registry --input {"keyPath":"HKLM\\CustomPath"}` will check if the property `keyPath` exists.
285
+
286
+
The following YAML snippet illustrates the `Test` capability:
287
+
288
+
```yaml
289
+
TestMethod:
290
+
type: object
291
+
required:
292
+
- executable
293
+
properties:
294
+
executable:
295
+
description: The command to run to test the state of the resource.
296
+
type: string
297
+
args:
298
+
description: The arguments to pass to the command to perform a Test.
299
+
type:
300
+
- array
301
+
- 'null'
302
+
items:
303
+
$ref: '#/definitions/ArgKind'
304
+
input:
305
+
description: How to pass required input for a Test.
306
+
anyOf:
307
+
- $ref: '#/definitions/InputKind'
308
+
- type: 'null'
309
+
return:
310
+
description: The type of return value expected from the Test method.
311
+
anyOf:
312
+
- $ref: '#/definitions/ReturnKind'
313
+
- type: 'null
314
+
```
315
+
316
+
There is a slight difference between the elements from the `Get` capability. The `ReturnKind` definition returns a value expected from the `test` method.
"$comment": "While the enumeration for return kind is the same for the `set` and `test`\nmethod, the way it changes the behavior of the command isn't. The description\nkeyword isn't included here because the respective schemas for those methods\ndocument the behavior themselves."
330
+
}
331
+
```
332
+
333
+
Again, `Microsoft.Windows/Registry` DSC resource is a resource to illustrate this. If you had invoked the command earlier to test if the `keyPath` existed, you would have noticed two properties returned:
334
+
335
+
-`inDesiredState`
336
+
-`differingProperties`
337
+
338
+
Even thought the resource itself hasn't defined the `Test` capability in the resource manifest, `dsc` performs a synthetic test. The synthetic test attempts to look at the properties and adds any if it is different. In the following example, it shows when the path didn't exist:
339
+
340
+
```yaml
341
+
desiredState:
342
+
keyPath: HKLM\CustomPath
343
+
actualState:
344
+
keyPath: HKLM\CustomPath
345
+
_exist: false
346
+
inDesiredState: false
347
+
differingProperties:
348
+
- _exist
349
+
```
350
+
351
+
If it did, the `differingProperties` would have been an empty array `[]`. The returned properties are useful to see what properties aren't in the state you want them to be.
352
+
353
+
### Delete
354
+
355
+
The `Delete` capability has been added in the engine to simplify resource authoring and provide a clear distinction from the `Set` capability. While `Set` is responsible for creating or updating a resource to match a desired state, `Delete` specifically handles the removal of resource instances. This separation makes the logical code flow in the engine less.
356
+
357
+
Learning about the `Delete` capability is done later when you will learn about configuration documents.
0 commit comments