Edit

Share via


dsc config export

Synopsis

Generates a configuration document that defines the existing instances of a set of resources.

Syntax

Configuration document from file

dsc config export [Options] --file <FILE>

Configuration document from option string

dsc config export [Options] --input <INPUT>

Configuration document from stdin

cat <FILE> | dsc config export [Options] --file -

Description

The export subcommand generates a configuration document that includes every instance of a set of resources.

The configuration document must be passed to this command as JSON or YAML with the --input or --file option.

The input document defines the resources to export. DSC ignores any properties specified for the resources in the input configuration for the operation, but the input document and any properties for resource instances must still validate against the configuration document and resource instance schemas.

Only specify resources with a resource manifest that defines the export section in the input configuration. Only define each resource type once. If the configuration document includes any resource instance where the resource type isn't exportable or has already been declared in the configuration, DSC raises an error.

Examples

Example 1 - Test whether a configuration's resource instances are in the desired state

The command inspects the system to return a configuration document containing every discovered instance of the resources defined in the configuration document saved as example.dsc.config.yaml. It passes the configuration document to the command from stdin using the --file option.

# example.dsc.config.yaml
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
resources:
- name: Operating system information
  type: Microsoft/OSInfo
  properties: {}
- name: Processes
  type: Microsoft/Process
  properties: {}
cat ./example.dsc.config.yaml | dsc config export --file -

Example 2 - Passing a file to read as the configuration document

The command uses the --file option to export resources from the configuration defined in the example.dsc.config.yaml file.

dsc config export --file ./example.dsc.config.yaml

Example 3 - Passing a configuration document as a variable

The command uses the --input option to exoirt resources from the configuration stored in the $desired variable.

dsc config export --input $desired

Options

-i, --input

Specifies the configuration document to validate state for.

The document must be a string containing a JSON or YAML object. DSC validates the document against the configuration document schema. If the validation fails, DSC raises an error.

This option is mutually exclusive with the --file option.

Type        : string
Mandatory   : false
LongSyntax  : --input <INPUT>
ShortSyntax : -i <INPUT>

-f, --file

Defines the path to a configuration document to validate state for.

The specified file must contain a configuration document as a JSON or YAML object. DSC validates the document against the configuration document schema. If the validation fails, or if the specified file doesn't exist, DSC raises an error.

You can also use this option to pass a configuration document from stdin, as shown in Example 1.

This option is mutually exclusive with the --input option.

Type        : string
Mandatory   : false
LongSyntax  : --file <FILE>
ShortSyntax : -f <FILE>

-o, --output-format

The --output-format option controls which format DSC uses for the data the command returns. The available formats are:

  • json to emit the data as a JSON Line.
  • pretty-json to emit the data as JSON with newlines, indentation, and spaces for readability.
  • yaml to emit the data as YAML.

The default output format depends on whether DSC detects that the output is being redirected or captured as a variable:

  • If the command isn't being redirected or captured, DSC displays the output as the yaml format in the console.
  • If the command output is redirected or captured, DSC emits the data as the json format to stdout.

When you use this option, DSC uses the specified format regardless of whether the command is being redirected or captured.

When the command isn't redirected or captured, the output in the console is formatted for improved readability. When the command isn't redirected or captured, the output include terminal sequences for formatting.

Type        : string
Mandatory   : false
ValidValues : [json, pretty-json, yaml]
LongSyntax  : --output-format <OUTPUT_FORMAT>
ShortSyntax : -o <OUTPUT_FORMAT>

-h, --help

Displays the help for the current command or subcommand. When you specify this option, the application ignores all other options and arguments.

Type        : boolean
Mandatory   : false
LongSyntax  : --help
ShortSyntax : -h

Output

This command returns formatted data that defines a configuration document including every instance of the resources declared in the input configuration. For more information, see DSC Configuration document schema reference.

For more information about the formatting of the output data, see the --output-format option.