DSCv3 Documentation

repository·main·Indexed 19 days ago

https://github.com/powershell/dsc

Documentation for DSCv3, a cross-platform, dependency-free command-line tool for declarative system management. It allows for multi-language resource authoring (Bash, Python, C#, Go) and uses JSON or YAML configuration documents to manage system state without a dependency on PowerShell or a Local Configuration Manager (LCM). Includes details on the `dsc` CLI subcommands, JSON schemas, and specific resources like Microsoft.Windows/UpdateList and osinfo.

Tokens
248.1K
Snippets
722
Records
1K
Agent score
64%

What's inside DSCv3

  1. What is Microsoft Desired State Configuration (DSCv3)?

    main

    Microsoft Desired State Configuration (DSC) is a declarative configuration platform used to describe the desired state of a machine. Unlike imperative tools, DSC separates the definition of an environment from the programming logic that enforces it.

    The dsc command-line application abstracts the management of software components declaratively and idempotently. It runs on Linux, macOS, and Windows without external dependencies.

    Key capabilities include:

    • Authoring Resources: Create DSC Resources in any language (Bash, Python, C#, Rust, etc.) to manage system state.
    • Direct Invocation: Invoke individual resources directly via the CLI.
    • Configuration Documents: Create declarative data files (JSON or YAML) that define the desired state of a system.
  2. Overview of DSC built-in tools

    main

    DSC includes built-in command-line tools designed to provide early feedback and support specific DSC resources. The available tools depend on your operating system:

    • osinfo: Available on Linux, macOS, and Windows. It returns operating system information in JSON format and supports the Microsoft/OSInfo DSC resource.
    • registry: Available on Windows only. It is used to manage registry keys and values and supports the Microsoft.Windows/Registry DSC resource.
  3. What is DSCv3?

    main

    DSCv3 is an open-source command-line application that provides a declarative and idempotent way to manage software components. Unlike its predecessor, DSCv3 is platform-agnostic and does not require PowerShell to run.

    Key Capabilities:

    • Multi-language Resource Authoring: Author resources in any language (e.g., Bash, Python, C#, Go).
    • Resource Invocation: Invoke individual resources directly via the CLI.
    • Configuration Documents: Create documents that define the desired state of a system using JSON or YAML.

    Core Differences from PowerShell DSC:

    • No PowerShell Dependency: Can run without PowerShell installed.
    • No Local Configuration Manager (LCM): DSCv3 is invoked as a command rather than running as a background service.
    • Schema Format: Non-PowerShell resources use JSON files for schemas instead of MOF files.
    • Configuration Format: Configuration documents use JSON or YAML instead of PowerShell script files.
    • Resource Compatibility: While configuration documents are not compatible, DSCv3 can still invoke existing PowerShell DSC Resources (script-based and class-based) on both Windows PowerShell and PowerShell.
  4. Manage Windows Optional features with Microsoft.Windows/OptionalFeatureList

    main

    The Microsoft.Windows/OptionalFeatureList resource allows you to idempotently manage Windows Optional features (like Hyper-V, WSL, or IIS) using the DISM API.

    Capabilities

    • Get: Retrieve the current state of one or more optional features.
    • Set: Enforce a desired state (Installed, NotPresent, or Removed) for features.
    • Export: Enumerate all optional features on the system with optional filtering.

    Requirements

    • Must be run on a Windows system.
    • Requires an elevated (administrator) process context.

    Installation

    This resource is installed automatically with DSC on Windows systems. To update it, simply update DSC.

    resources:
      - name: manage-hyperv
        type: Microsoft.Windows/OptionalFeatureList
        properties:
          features:
            - featureName: Microsoft-Hyper-V-All
              state: Installed
  5. Identify and use built-in DSC resources

    main

    DSCv3 includes several built-in resources available immediately after installation. These resources are categorized by their primary function: asserting state, adapting existing tools, changing machine state, debugging, or managing resource groups.

    Resource Categories

    • Assertion Resources: Used to query the current state of a machine without modifying it. Examples include Microsoft/OSInfo, Microsoft.DSC/Assertion, and Microsoft.Windows/RebootPending.
    • Adapter Resources: Used to leverage existing tools that do not have a native DSC Resource Manifest. Examples include Microsoft.Adapter/PowerShell, Microsoft.Adapter/WindowsPowerShell, and Microsoft.Windows/WMI.
    • Configurable Resources: Used to directly change the state of a machine. Examples include Microsoft.DSC.Transitional/RunCommandOnSet and Microsoft.Windows/Registry.
    • Debugging Resources: Used for exploring or debugging DSC configurations without affecting the machine state. Example: Microsoft.DSC.Debug/Echo.
    • Group Resources: Used to control how DSC processes groups of nested resource instances. Examples include Microsoft.DSC/Assertion, Microsoft.DSC/Group, and Microsoft.DSC/Include.
  6. Manage Windows Registry with Microsoft.Windows/Registry

    main

    The Microsoft.Windows/Registry resource allows you to idempotently manage Windows Registry keys and values. You can use it to add, update, or remove registry keys and values.

    IMPORTANT

    The registry command and Microsoft.Windows/Registry resource are a proof-of-concept example for use with DSC. Don't use it in production.

    Capabilities

    • get: Retrieve the actual state of an instance.
    • set: Enforce the desired state.
    • whatIf: Report how changes would be made without applying them.
    • delete: Directly remove an instance from the system.

    Requirements

    • Must be run on a Windows system.
    • The process must have sufficient permissions to manage the keys in the hive specified by keyPath.
    resources:
      - name: <instance name>
        type: Microsoft.Windows/Registry
        properties:
          keyPath: string
          _exist: <boolean>
          valueName: <string>
          valueData: <object>
  7. Use the Microsoft.Windows/FirewallRuleList resource

    main

    The Microsoft.Windows/FirewallRuleList resource allows for idempotent management of Windows Firewall rules via the netfw.h COM APIs. A single resource instance manages an array of rules, enabling you to create, update, or remove multiple rules in a single operation.

    Key Capabilities

    • Retrieve State: Get the current configuration of specific named firewall rules.
    • Manage Rules: Create new rules, update existing ones, or remove rules by setting _exist: false.
    • Export Rules: Export all registered firewall rules on the system, with optional filtering by rule properties.

    Requirements

    • Platform: Windows only.
    • Privileges: Both set and export operations require an elevated (administrator) process context. Running these in a non-elevated context will result in an error.

    Important: The _exist Property Behavior

    The _exist property behaves differently than standard DSC resources:

    • If a rule exists in the Windows Firewall store, the _exist field is omitted from the returned state (meaning the rule is present).
    • If a rule is not found, _exist: false will appear in the response.
    • Therefore, a missing _exist field in the actual state indicates the rule exists.
    resources:
      - name: <instance name>
        type: Microsoft.Windows/FirewallRuleList
        properties:
          rules:
            - name: string
              action:
              applicationName:
              description:
              direction:
              edgeTraversal:
              enabled:
              grouping:
              interfaceTypes:
              localAddresses:
              localPorts:
              profiles:
              protocol:
              remoteAddresses:
              remotePorts:
              serviceName:
              _exist: false # Use to remove a rule
  8. Manage Windows services with Microsoft.Windows/Service

    main

    The Microsoft.Windows/Service resource allows you to idempotently manage the configuration and runtime state of Windows services registered with the Service Control Manager (SCM).

    Capabilities

    • get: Retrieve the actual state of a service instance.
    • set: Enforce a desired configuration or status (requires elevated/administrator privileges).
    • export: Export a list of all services registered on the system.

    Requirements

    • Platform: Windows only.
    • Privileges: Set operations require an elevated (administrator) process context. Running dsc without elevation during a Set operation will result in an access-denied error from the SCM.

    Installation

    This resource is installed automatically with DSC on Windows systems. To update the resource, update DSC itself.

  9. Use the `dsc` command to manage DSC resources

    main

    The dsc command is the primary interface for discovering and invoking Desired State Configuration (DSC) resources, as well as applying configuration documents. It provides subcommands for managing configurations, interacting with extensions, invoking individual resources, and retrieving JSON schemas for DSC types.

    dsc.exe [OPTIONS] <COMMAND>
  10. Use the osinfo resource to retrieve OS information

    main
    The osinfo resource is an assertion-type resource used to retrieve basic operating system information. It does not accept configuration input and does not include a JSON schema. It is primarily used to demonstrate how DSC handles resources where the test operation is synthetically implemented by the DSC engine rather than the resource itself.
  11. Manage macOS packages with DSC.PackageManagement/Brew

    main

    The DSC.PackageManagement/Brew resource allows you to idempotently manage Homebrew packages on macOS systems. You can use it to install, uninstall, check for existence, or verify the version of a package.

    IMPORTANT

    This resource is a proof-of-concept example. Do not use it in production environments.

    Requirements

    • A macOS system with Homebrew installed.
    • Administrative privileges may be required for certain operations.
  12. Manage Windows Features on Demand with Microsoft.Windows/FeatureOnDemandList

    main

    The Microsoft.Windows/FeatureOnDemandList resource allows you to idempotently manage Windows features on demand (capabilities) using the DISM API. This is useful for managing optional components like language packs, OpenSSH, or RSAT tools.

    Key Operations

    • Get: Retrieve the current state of capabilities by their identity.
    • Set: Enforce a desired state (Installed or NotPresent) for specific capabilities.
    • Export: Enumerate all capabilities on the system, with optional filtering by identity, state, displayName, or description (supports wildcards).

    Requirements

    • Must be run on a Windows system.
    • Requires an elevated (administrator) process context.
    • Installing capabilities may require internet access or a configured Windows Update / WSUS source.

    Installation Note

    This resource is installed automatically with DSC on Windows systems. To update the resource, update DSC itself.

    resources:
      - name: <instance name>
        type: Microsoft.Windows/FeatureOnDemandList
        properties:
          capabilities:
            - identity: string
              state: Installed | NotPresent