1
1
---
2
2
description : Command line reference for the 'dsc config export' command
3
- ms.date : 09/06/2023
3
+ ms.date : 3/05/2025
4
4
ms.topic : reference
5
5
title : dsc config export
6
6
---
@@ -13,33 +13,33 @@ Generates a configuration document that defines the existing instances of a set
13
13
14
14
## Syntax
15
15
16
- ### Configuration document from stdin
16
+ ### Configuration document from file
17
17
18
18
``` sh
19
- < document-string > | dsc config export [Options]
19
+ dsc config export [Options] --file < FILE >
20
20
```
21
21
22
22
### Configuration document from option string
23
23
24
24
``` sh
25
- dsc config export [Options] --document < document-string >
25
+ dsc config export [Options] --input < INPUT >
26
26
```
27
27
28
- ### Configuration document from file
28
+ ### Configuration document from stdin
29
29
30
30
``` sh
31
- dsc config export [Options] --path < document-filepath >
31
+ cat < FILE > | dsc config export [Options] --file -
32
32
```
33
33
34
34
## Description
35
35
36
36
The ` export ` subcommand generates a configuration document that includes every instance of a set of
37
37
resources.
38
38
39
- The configuration document must be passed to this command as JSON or YAML over stdin, as a string
40
- with the ** document ** option, or from a file with the ** path ** option.
39
+ The configuration document must be passed to this command as JSON or YAML with the ` --input ` or
40
+ ` -- file` option.
41
41
42
- The input configuration defines the resources to export. DSC ignores any properties specified for
42
+ The input document defines the resources to export. DSC ignores any properties specified for
43
43
the resources in the input configuration for the operation, but the input document and any
44
44
properties for resource instances must still validate against the configuration document and
45
45
resource instance schemas.
@@ -49,65 +49,158 @@ configuration. Only define each resource type once. If the configuration documen
49
49
resource instance where the resource type isn't exportable or has already been declared in the
50
50
configuration, DSC raises an error.
51
51
52
+ ## Examples
53
+
54
+ ### Example 1 - Test whether a configuration's resource instances are in the desired state
55
+
56
+ <a id =" example-1 " ></a >
57
+
58
+ The command inspects the system to return a configuration document containing every discovered
59
+ instance of the resources defined in the configuration document saved as ` example.dsc.config.yaml ` .
60
+ It passes the configuration document to the command from stdin using the ` --file ` option.
61
+
62
+ ``` yaml
63
+ # example.dsc.config.yaml
64
+ $schema : https://aka.ms/dsc/schemas/v3/bundled/config/document.json
65
+ resources :
66
+ - name : Operating system information
67
+ type : Microsoft/OSInfo
68
+ properties : {}
69
+ - name : Processes
70
+ type : Microsoft/Process
71
+ properties : {}
72
+ ` ` `
73
+
74
+ ` ` ` sh
75
+ cat ./example.dsc.config.yaml | dsc config export --file -
76
+ ```
77
+
78
+ ### Example 2 - Passing a file to read as the configuration document
79
+
80
+ <a id =" example-2 " ></a >
81
+
82
+ The command uses the ` --file ` option to export resources from the configuration defined in the
83
+ ` example.dsc.config.yaml ` file.
84
+
85
+ ``` sh
86
+ dsc config export --file ./example.dsc.config.yaml
87
+ ```
88
+
89
+ ### Example 3 - Passing a configuration document as a variable
90
+
91
+ <a id =" example-3 " ></a >
92
+
93
+ The command uses the ` --input ` option to exoirt resources from the configuration stored in the
94
+ ` $desired ` variable.
95
+
96
+ ``` sh
97
+ dsc config export --input $desired
98
+ ```
99
+
52
100
## Options
53
101
54
- ### -d, --document
102
+ ### -i, --input
103
+
104
+ <a id =" -i " ></a >
105
+ <a id =" --input " ></a >
106
+
107
+ Specifies the configuration document to validate state for.
55
108
56
- Specifies the configuration document to export from as a JSON or YAML object. DSC validates the
57
- document against the configuration document schema. If the validation fails, DSC raises an error.
109
+ The document must be a string containing a JSON or YAML object. DSC validates the document against
110
+ the configuration document schema. If the validation fails, DSC raises an error.
58
111
59
- This option can't be used with configuration document over stdin or the ` --path ` option. Choose
60
- whether to pass the configuration document to the command over stdin, from a file with the ` --path `
61
- option, or with the ` --document ` option.
112
+ This option is mutually exclusive with the ` --file ` option.
62
113
63
114
``` yaml
64
- Type : String
65
- Mandatory : false
115
+ Type : string
116
+ Mandatory : false
117
+ LongSyntax : --input <INPUT>
118
+ ShortSyntax : -i <INPUT>
66
119
` ` `
67
120
68
- ### -p, --path
121
+ ### -f, --file
122
+
123
+ <a id="-f"></a>
124
+ <a id="--file"></a>
125
+
126
+ Defines the path to a configuration document to validate state for.
69
127
70
- Defines the path to a configuration document to export instead of piping the document from stdin or
71
- passing it as a string with the ` --document` option. The specified file must contain a
72
- configuration document as a JSON or YAML object. DSC validates the document against the
73
- configuration document schema. If the validation fails, or if the specified file doesn't exist, DSC
74
- raises an error.
128
+ The specified file must contain a configuration document as a JSON or YAML object. DSC validates
129
+ the document against the configuration document schema. If the validation fails, or if the
130
+ specified file doesn't exist, DSC raises an error.
75
131
76
- This option is mutually exclusive with the `--document` option. When you use this option, DSC
77
- ignores any input from stdin.
132
+ You can also use this option to pass a configuration document from stdin, as shown in
133
+ [Example 1](#example-1).
134
+
135
+ This option is mutually exclusive with the ` --input` option.
78
136
79
137
` ` ` yaml
80
- Type: String
81
- Mandatory: false
138
+ Type : string
139
+ Mandatory : false
140
+ LongSyntax : --file <FILE>
141
+ ShortSyntax : -f <FILE>
82
142
` ` `
83
143
84
- # ## -f, --format
144
+ # ## -o, --output-format
145
+
146
+ <a id="-o"></a>
147
+ <a id="--output-format"></a>
148
+
149
+ The `--output-format` option controls which format DSC uses for the data the command returns. The
150
+ available formats are :
151
+
152
+ - ` json` to emit the data as a [JSON Line][02].
153
+ - ` pretty-json` to emit the data as JSON with newlines, indentation, and spaces for readability.
154
+ - ` yaml` to emit the data as YAML.
155
+
156
+ The default output format depends on whether DSC detects that the output is being redirected or
157
+ captured as a variable :
85
158
86
- The `--format` option controls the console output format for the command. If the command output is
87
- redirected or captured as a variable, the output is always JSON.
159
+ - If the command isn't being redirected or captured, DSC displays the output as the `yaml` format
160
+ in the console.
161
+ - If the command output is redirected or captured, DSC emits the data as the `json` format to
162
+ stdout.
163
+
164
+ When you use this option, DSC uses the specified format regardless of whether the command is being
165
+ redirected or captured.
166
+
167
+ When the command isn't redirected or captured, the output in the console is formatted for improved
168
+ readability. When the command isn't redirected or captured, the output include terminal sequences
169
+ for formatting.
88
170
89
171
` ` ` yaml
90
- Type: String
91
- Mandatory: false
92
- DefaultValue: yaml
93
- ValidValues: [json, pretty-json, yaml]
172
+ Type : string
173
+ Mandatory : false
174
+ ValidValues : [json, pretty-json, yaml]
175
+ LongSyntax : --output-format <OUTPUT_FORMAT>
176
+ ShortSyntax : -o <OUTPUT_FORMAT>
94
177
` ` `
95
178
96
179
# ## -h, --help
97
180
181
+ <a id="-h"></a>
182
+ <a id="--help"></a>
183
+
98
184
Displays the help for the current command or subcommand. When you specify this option, the
99
- application ignores all options and arguments after this one .
185
+ application ignores all other options and arguments.
100
186
101
187
` ` ` yaml
102
- Type: Boolean
103
- Mandatory: false
188
+ Type : boolean
189
+ Mandatory : false
190
+ LongSyntax : --help
191
+ ShortSyntax : -h
104
192
` ` `
105
193
106
194
# # Output
107
195
108
- This command returns JSON output that defines a configuration document including every instance of
109
- the resources declared in the input configuration. For more information, see
110
- [DSC Configuration document schema reference][02].
196
+ This command returns formatted data that defines a configuration document including every instance
197
+ of the resources declared in the input configuration. For more information, see
198
+ [DSC Configuration document schema reference][03].
199
+
200
+ For more information about the formatting of the output data, see the
201
+ [--output-format option](#--output-format).
111
202
203
+ <!-- Link reference definitions -->
112
204
[01] : ../../schemas/resource/manifest/export.md
113
- [02] : ../../schemas/config/document.md
205
+ [02] : https://jsonlines.org/
206
+ [03] : ../../schemas/config/document.md
0 commit comments