### Get DSC Configuration State Source: https://github.com/powershell/dsc/blob/main/docs/get-started/index.md Demonstrates how to retrieve the current state of a DSC configuration using the `dsc config get` command. This command is useful for auditing and verifying the system's state against a desired configuration. ```powershell dsc config get --file ./example.dsc.config.yaml ``` -------------------------------- ### Define Registry Instance for Get Operation Source: https://github.com/powershell/dsc/blob/main/docs/get-started/index.md Defines a PowerShell hashtable representing a specific registry key and value, which is then converted to JSON to be used as input for the `dsc resource get` command. ```powershell $instance = @{ keyPath = 'HKLM\Software\Microsoft\Windows NT\CurrentVersion' valueName = 'SystemRoot' } | ConvertTo-Json ``` -------------------------------- ### Example 1 - Minimal definition command execution Source: https://github.com/powershell/dsc/blob/main/docs/reference/schemas/resource/manifest/get.md Illustrates the command line execution for a minimal 'get' definition, where input is piped to the executable. ```sh { ... } | osinfo ``` -------------------------------- ### DSC Configuration Document Source: https://github.com/powershell/dsc/blob/main/docs/get-started/index.md Defines the desired state of a system, including registry keys and environment variables, using YAML format. ```yaml $schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json resources: - name: Example registry key type: Microsoft.Windows/Registry properties: keyPath: HKCU\dsc\example\key _exist: true - name: PSDSC resources type: Microsoft.Windows/WindowsPowerShell properties: resources: - name: DSC_EXAMPLE env variable type: PSDesiredStateConfiguration/Environment properties: Name: DSC_EXAMPLE Ensure: Present Value: Set by DSC ``` -------------------------------- ### Get Current State of Registry Resource Source: https://github.com/powershell/dsc/blob/main/docs/get-started/index.md Retrieves the current state of a specified registry instance using the `dsc resource get` command. It requires the resource type and the JSON-formatted instance data as input. ```powershell dsc resource get --resource $resource.type --input $instance ``` -------------------------------- ### DSC Configuration Get Operation Output Source: https://github.com/powershell/dsc/blob/main/docs/get-started/index.md Illustrates the structure of the output when retrieving DSC configuration state. The output details the metadata of the operation, including start/end times and duration, followed by results for each resource, specifying their type, name, and actual state. ```yaml metadata: Microsoft.DSC: version: 3.0.0 operation: get executionType: actual startDatetime: 2025-03-03T17:16:39.507848200-06:00 endDatetime: 2025-03-03T17:16:47.734256600-06:00 duration: PT8.2264084S securityContext: elevated results: - metadata: Microsoft.DSC: duration: PT0.1739569S name: Example registry key type: Microsoft.Windows/Registry result: actualState: keyPath: HKCU\dsc\example\key - metadata: Microsoft.DSC: duration: PT3.9958946S name: PSDSC resources type: Microsoft.Windows/WindowsPowerShell result: actualState: result: - name: DSC_EXAMPLE env variable type: PSDesiredStateConfiguration/Environment properties: ResourceId: null PsDscRunAsCredential: null PSComputerName: localhost ModuleVersion: '1.1' Value: Set by DSC Path: null ConfigurationName: null Name: DSC_EXAMPLE ModuleName: PSDesiredStateConfiguration SourceInfo: null DependsOn: null Ensure: Present messages: [] hadErrors: false ``` -------------------------------- ### List and Group DSC Resources by Adapter Source: https://github.com/powershell/dsc/blob/main/docs/get-started/index.md This snippet demonstrates how to list all DSC resources, convert the output to JSON, and then group them by the adapter they require. It also shows the resulting table output. ```powershell $adaptedResources = dsc resource list --adapter * | ConvertFrom-Json $adaptedResources | Group-Object -NoElement -Property requireAdapter | Format-Table -AutoSize ``` -------------------------------- ### DSC Resource Capabilities Explained Source: https://github.com/powershell/dsc/blob/main/docs/get-started/index.md Details the capabilities of DSC resources as indicated by flags in the output of `dsc resource list`. These flags represent functionalities like get (`g`), set (`s`), test (`t`), and more. ```APIDOC DSC Resource Capabilities: g: get capability s: set capability x: setHandlesExist capability w: whatIf capability t: test capability d: delete capability e: export capability r: resolve capability ``` -------------------------------- ### Input from stdin example Source: https://github.com/powershell/dsc/blob/main/docs/reference/schemas/resource/manifest/get.md Illustrates a 'get' property definition where input is explicitly sent via stdin. This example includes the 'executable' and 'input' properties, along with additional arguments for the command. ```json "get": { "executable": "registry", "args": [ "config", "get" ], "input": "stdin" } ``` -------------------------------- ### DSC Resource Kinds Explained Source: https://github.com/powershell/dsc/blob/main/docs/get-started/index.md Explains the different kinds of DSC resources: Adapter, Group, Importer, and Resource. Each kind defines how the resource is used within DSC. ```APIDOC DSC Resource Kinds: Adapter: Configures components without their own DSC resource manifest (e.g., PSDSC resources). Group: Processes a list of resource instances as a group; does not directly manage state. Importer: Retrieves configuration documents from external sources. Resource: A typical resource that directly manages state. ``` -------------------------------- ### List Available DSC Resources Source: https://github.com/powershell/dsc/blob/main/docs/get-started/index.md Enumerates all DSC resources discovered on the system. DSC finds resources by searching folders in the PATH environment variable for files with specific suffixes like `.dsc.resource.json` or `.dsc.resource.yaml`. ```powershell dsc resource list ``` -------------------------------- ### List Registry Resource Capabilities Source: https://github.com/powershell/dsc/blob/main/docs/get-started/index.md Lists the capabilities of the Microsoft.Windows/Registry resource to understand what operations can be performed on it. This involves using `dsc resource list` and converting the output to JSON. ```powershell $resource = dsc resource list Microsoft.Windows/Registry | ConvertFrom-Json $resource.capabilities ``` -------------------------------- ### DSC Get Capability Output Source: https://github.com/powershell/dsc/blob/main/docs/reference/resources/Microsoft/DSC/Debug/echo/examples/basic-echo-example.md Illustrates the output from the 'get' capability of the Microsoft.DSC.Debug/Echo resource, which returns the value provided in the output property. ```yaml actualState: output: Hello World! ``` -------------------------------- ### Example 2 - Input from stdin command execution Source: https://github.com/powershell/dsc/blob/main/docs/reference/schemas/resource/manifest/get.md Shows the command line execution for a 'get' definition using stdin input, including the executable and arguments. ```sh { ... } | registry config get ``` -------------------------------- ### Test DSC Configuration Source: https://github.com/powershell/dsc/blob/main/docs/get-started/index.md Tests a DSC configuration document to check if the system is in the desired state. Requires elevated permissions. ```powershell dsc config test --file ./example.dsc.config.yaml ``` -------------------------------- ### Example 1: Get current state from stdin Source: https://github.com/powershell/dsc/blob/main/docs/reference/cli/config/get.md Demonstrates how to retrieve the actual state of resource instances by piping a DSC configuration document from stdin to the 'dsc config get' command. ```powershell cat ./example.dsc.config.yaml | dsc config get --file - ``` -------------------------------- ### Example 3 - JSON input argument command execution Source: https://github.com/powershell/dsc/blob/main/docs/reference/schemas/resource/manifest/get.md Demonstrates the command line execution for a 'get' definition using a JSON input argument, passing the compressed JSON data to the specified argument. ```sh tstoy config get --input "{ ... }" ``` -------------------------------- ### DSC Configuration Test Results Source: https://github.com/powershell/dsc/blob/main/docs/get-started/index.md Provides the results of testing a DSC configuration, indicating which resources are in the desired state and which are not. ```yaml metadata: Microsoft.DSC: version: 3.0.0 operation: test executionType: actual startDatetime: 2025-03-03T17:11:25.726475600-06:00 endDatetime: 2025-03-03T17:11:32.567311800-06:00 duration: PT6.8408362S securityContext: elevated results: - metadata: Microsoft.DSC: duration: PT0.1818183S name: Example registry key type: Microsoft.Windows/Registry result: desiredState: keyPath: HKCU\dsc\example\key _exist: true actualState: keyPath: HKCU\dsc\example\key inDesiredState: true differingProperties: [] - metadata: Microsoft.DSC: duration: PT3.0461988S name: PSDSC resources type: Microsoft.Windows/WindowsPowerShell result: desiredState: resources: - name: DSC_EXAMPLE env variable type: PSDesiredStateConfiguration/Environment properties: Name: DSC_EXAMPLE Ensure: Present Value: Set by DSC metadata: Microsoft.DSC: context: configuration actualState: result: - name: DSC_EXAMPLE env variable type: PSDesiredStateConfiguration/Environment properties: InDesiredState: false inDesiredState: false differingProperties: - resources - metadata messages: [] hadErrors: false ``` -------------------------------- ### DSC Configuration Set Results Source: https://github.com/powershell/dsc/blob/main/docs/get-started/index.md Details the results of enforcing a DSC configuration, showing changes made to resources to match the desired state. ```yaml metadata: Microsoft.DSC: version: 3.0.0 operation: set executionType: actual startDatetime: 2025-03-03T17:14:15.841393700-06:00 endDatetime: 2025-03-03T17:14:29.136469500-06:00 duration: PT13.2950758S securityContext: elevated results: - metadata: Microsoft.DSC: duration: PT0.2633556S name: Example registry key type: Microsoft.Windows/Registry result: beforeState: keyPath: HKCU\dsc\example\key _exist: true afterState: keyPath: HKCU\dsc\example\key changedProperties: null - metadata: Microsoft.DSC: duration: PT8.6601181S name: PSDSC resources type: Microsoft.Windows/WindowsPowerShell result: beforeState: result: - name: DSC_EXAMPLE env variable type: PSDesiredStateConfiguration/Environment properties: ResourceId: null PsDscRunAsCredential: null PSComputerName: localhost ModuleVersion: '1.1' ``` -------------------------------- ### Minimal get definition example Source: https://github.com/powershell/dsc/blob/main/docs/reference/schemas/resource/manifest/get.md Demonstrates a minimal 'get' property definition for a DSC Resource manifest, using only the 'executable' property. DSC defaults to passing input via stdin when 'input' is not specified. ```json "get": { "executable": "osinfo" } ``` -------------------------------- ### Set DSC Configuration Source: https://github.com/powershell/dsc/blob/main/docs/get-started/index.md Enforces the desired state defined in a DSC configuration document on the system. Requires elevated permissions. ```powershell dsc config set --file ./example.dsc.config.yaml ``` -------------------------------- ### Display Resources for a Specific Adapter Source: https://github.com/powershell/dsc/blob/main/docs/get-started/index.md This snippet filters the previously obtained list of adapted resources to show only those that require the 'Microsoft.Windows/WindowsPowerShell' adapter. It then displays specific properties of these resources in a table. ```powershell $adaptedResources | Where-Object -Property requireAdapter -eq Microsoft.Windows/WindowsPowerShell | Format-Table -Property type, kind, version, capabilities, description ``` -------------------------------- ### Get Registry Value Example Source: https://github.com/powershell/dsc/blob/main/docs/reference/tools/registry/config/get.md Illustrates how to retrieve the current state of a specified registry value using the 'registry config get' command. It includes examples for when the key exists but the value does not, and when the key itself does not exist. ```powershell $instance = @{ keyPath = 'HKLM\Software\Microsoft\Windows NT\CurrentVersion' valueName = 'SystemRoot' } | ConvertTo-Json registry config get --input $instance | ConvertFrom-Json | Format-List ``` ```output keyPath : HKLM\Software\Microsoft\Windows NT\CurrentVersion valueName : SystemRoot valueData : @{String=C:\WINDOWS} ``` ```powershell $instance = @{ keyPath = 'HKLM\Software\Microsoft\Windows NT\DoesNotExist' valueName = 'SystemRoot' } | ConvertTo-Json registry config get --input $instance | ConvertFrom-Json | Format-List ``` ```output keyPath : HKLM\Software\Microsoft\Windows NT\DoesNotExist _exist : False ``` ```powershell $instance = @{ keyPath = 'HKLM\Software\Microsoft\Windows NT\CurrentVersion' valueName = 'DoesNotExist' } | ConvertTo-Json registry config get --input $instance | ConvertFrom-Json | Format-List ``` ```output keyPath : HKLM\Software\Microsoft\Windows NT\CurrentVersion valueName : DoesNotExist _exist : False ``` -------------------------------- ### DSC Resource Get with JSON Input (Working Examples) Source: https://github.com/powershell/dsc/blob/main/docs/troubleshooting/known-issues.md Demonstrates correct methods for passing JSON input to DSC resource get commands in PowerShell. These examples bypass common compression-related issues. ```powershell dsc resource get -r PSDesiredStateConfiguration/Service --input '{ "Name": "bits" }' ``` ```powershell dsc resource get -r PSDesiredStateConfiguration/Service --input (@{Name = 'bits'} | ConvertTo-Json) ``` -------------------------------- ### String Starting with Bracket Source: https://github.com/powershell/dsc/blob/main/tree-sitter-dscexpression/test/corpus/invalid_expressions.txt Demonstrates a string that starts with a bracket but is not a valid expression, leading to a parsing error. ```powershell [Test] string ``` -------------------------------- ### Example 2: Get current state from file Source: https://github.com/powershell/dsc/blob/main/docs/reference/cli/config/get.md Shows how to use the '--file' option to specify a DSC configuration document for the 'dsc config get' command. ```powershell dsc config get --path ./example.dsc.config.yaml ``` -------------------------------- ### List Adapted DSC Resources Source: https://github.com/powershell/dsc/blob/main/docs/get-started/index.md Retrieves a list of adapted DSC resources, which are resources that enable configuration of components without their own DSC resource manifest, such as PowerShell DSC (PSDSC) resources. This is achieved using the `--adapter` option. ```powershell dsc resource list --adapter ``` -------------------------------- ### Float Input Starting with Decimal Source: https://github.com/powershell/dsc/blob/main/tree-sitter-dscexpression/test/corpus/invalid_expressions.txt Illustrates a parsing error for a float number argument that starts with a decimal point. ```powershell [myFunction(.1)] ``` -------------------------------- ### Example: Setting a resource with the input option Source: https://github.com/powershell/dsc/blob/main/docs/reference/cli/resource/set.md Ensures the 'Example' key exists in the current user hive by passing the desired state as JSON using the `--input` option to the `dsc resource set` command. ```powershell dsc resource set --resource Microsoft.Windows/Registry --input '{ "keyPath": "HKCU\\Example", "_exist": true }' ``` -------------------------------- ### Example 3: Get current state from variable Source: https://github.com/powershell/dsc/blob/main/docs/reference/cli/config/get.md Illustrates using the '--input' option to pass a DSC configuration document stored in a variable to the 'dsc config get' command. ```powershell dsc config get --input $desired ``` -------------------------------- ### Example 3: Multi-prefix evaluation Source: https://github.com/powershell/dsc/blob/main/docs/reference/schemas/config/functions/startsWith.md Shows how to evaluate multiple potential prefixes for a given string using multiple calls to startsWith. Includes the DSC configuration YAML and the command to execute it. ```yaml $schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json parameters: name: type: string defaultValue: db-primary-01 resources: - name: Prefix grouping type: Microsoft.DSC.Debug/Echo properties: output: isDb: "[startsWith(parameters('name'), 'db-')]" isApi: "[startsWith(parameters('name'), 'api-')]" isCache: "[startsWith(parameters('name'), 'cache-')]" ``` ```bash dsc config get --file startswith.example.3.dsc.config.yaml ``` ```yaml results: - name: Prefix grouping type: Microsoft.DSC.Debug/Echo result: actualState: output: isDb: true isApi: false isCache: false messages: [] hadErrors: false ``` -------------------------------- ### Get DSC Resource State Source: https://github.com/powershell/dsc/blob/main/docs/reference/resources/Microsoft/DSC/Debug/echo/examples/basic-echo-example.md Demonstrates using the 'get' capability of the Microsoft.DSC.Debug/Echo resource to retrieve the current value of the output property. ```powershell $instance = @{ output = 'Hello World!' } | ConvertTo-Json dsc resource get --resource Microsoft.DSC.Debug/Echo --input $instance ``` -------------------------------- ### DSC Configuration Document Example Source: https://github.com/powershell/dsc/blob/main/docs/concepts/configuration-documents/overview.md An example of a minimal DSC configuration document in YAML format. It specifies the schema and defines a single resource instance for managing a registry key. ```yaml # example.dsc.config.yaml $schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json resources: - name: example key value type: Microsoft.Windows/Registry properties: keyPath: HKCU\example\key valueName: Example valueData: String: This is an example. ``` -------------------------------- ### DSCv3 Installation Source: https://github.com/powershell/dsc/blob/main/README.md Instructions for installing DSCv3, which involves downloading the latest release, expanding the archive, and adding the directory to the system's PATH environment variable. ```Shell 1. Download the [latest release from this repository][01]. 2. Expand the release archive. 3. Add the folder containing the expanded archive contents to the `PATH`. ``` -------------------------------- ### Example: Get OSInfo Resource Instance Source: https://github.com/powershell/dsc/blob/main/docs/reference/cli/resource/get.md Retrieves the actual state of the Microsoft.Windows/OSInfo resource without requiring any input properties. ```powershell dsc resource get --resource Microsoft/OSInfo ``` ```yaml actualState: $id: https://developer.microsoft.com/json-schemas/dsc/os_info/20230303/Microsoft.Dsc.OS_Info.schema.json family: Windows version: 10.0.22621 edition: Windows 11 Enterprise bitness: '64' ``` -------------------------------- ### Example: Setting a resource with properties from a YAML file Source: https://github.com/powershell/dsc/blob/main/docs/reference/cli/resource/set.md Ensures the 'Example' key exists in the current user hive by specifying the path to a YAML file containing the desired state with the `--file` option. ```yaml # ./example.yaml keyPath: HKCU\\Example _exist: true ``` ```powershell dsc resource set --resource Microsoft.Windows/Registry --path ./example.yaml ``` -------------------------------- ### Get Registry Key Example Source: https://github.com/powershell/dsc/blob/main/docs/reference/tools/registry/config/get.md Demonstrates how to retrieve the current state of a specified registry key using the 'registry config get' command. It shows the input JSON structure and the expected output when the key exists and when it does not. ```powershell $instance = @{ keyPath = 'HKLM\Software\Microsoft\Windows NT\CurrentVersion' } | ConvertTo-Json registry config get --input $instance ``` ```json {"keyPath":"HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion"} ``` ```powershell $instance = @{ keyPath = 'HKCU\Example\Nested\Key' } | ConvertTo-Json $instance | registry config get ``` ```json {"keyPath":"HKCU\\Example\\Nested\\Key","_exist":false} ``` -------------------------------- ### DSC Schema for Get Result Source: https://github.com/powershell/dsc/blob/main/docs/reference/cli/schema/index.md Example of retrieving the JSON schema for the 'get-result' DSC type. This schema defines the structure for the output of DSC get operations. ```APIDOC $schema: http://json-schema.org/draft-07/schema# title: GetResult anyOf: - $ref: '#/definitions/ResourceGetResponse' - type: array items: $ref: '#/definitions/ResourceGetResult' definitions: ResourceGetResponse: type: object required: - actualState properties: actualState: description: The state of the resource as it was returned by the Get method. additionalProperties: false ResourceGetResult: type: object required: - name - result - type properties: metadata: anyOf: - $ref: '#/definitions/Metadata' - type: 'null' name: type: string type: type: string result: $ref: '#/definitions/GetResult' additionalProperties: false Metadata: type: object properties: Microsoft.DSC: anyOf: - $ref: '#/definitions/MicrosoftDscMetadata' - type: 'null' MicrosoftDscMetadata: type: object properties: version: description: Version of DSC type: - string - 'null' operation: description: The operation being performed anyOf: - $ref: '#/definitions/Operation' - type: 'null' executionType: description: The type of execution anyOf: - $ref: '#/definitions/ExecutionKind' - type: 'null' startDatetime: description: The start time of the configuration operation type: - string - 'null' endDatetime: description: The end time of the configuration operation type: - string - 'null' duration: description: The duration of the configuration operation type: - string - 'null' securityContext: description: The security context of the configuration operation, can be specified to be required anyOf: - $ref: '#/definitions/SecurityContextKind' - type: 'null' context: description: Identifies if the operation is part of a configuration anyOf: - $ref: '#/definitions/ContextKind' - type: 'null' Operation: type: string enum: - Get - Set - Test - Export ExecutionKind: type: string enum: - Actual - WhatIf SecurityContextKind: type: string enum: - Current - Elevated - Restricted ContextKind: type: string enum: - Configuration - Resource GetResult: anyOf: - $ref: '#/definitions/ResourceGetResponse' - type: array items: $ref: '#/definitions/ResourceGetResult' ``` -------------------------------- ### DSC Config Test Examples Source: https://github.com/powershell/dsc/blob/main/docs/reference/cli/config/test.md Demonstrates how to use the 'dsc config test' command with different input methods. ```powershell cat ./example.dsc.config.yaml | dsc config test --file - ``` ```powershell dsc config test --file ./example.dsc.config.yaml ``` ```powershell dsc config test --input $desired ``` -------------------------------- ### DSC Configuration Document Example Source: https://github.com/powershell/dsc/blob/main/docs/reference/resources/Microsoft/Windows/Registry/examples/configure-registry-keys-and-values.md An example of a DSC configuration document in YAML format, detailing the desired state for registry keys and values, along with metadata about the operation. ```yaml metadata: Microsoft.DSC: version: 3.0.0 operation: set executionType: actual startDatetime: 2025-03-12T11:59:40.172845800-05:00 endDatetime: 2025-03-12T11:59:42.127979800-05:00 duration: PT1.955134S securityContext: restricted results: - metadata: Microsoft.DSC: duration: PT0.6354747S name: Managed key type: Microsoft.Windows/Registry result: beforeState: keyPath: HKCU\DscExamples\ManagedKey _exist: false afterState: keyPath: HKCU\DscExamples\ManagedKey changedProperties: - _exist - metadata: Microsoft.DSC: duration: PT0.2081512S name: Managed value type: Microsoft.Windows/Registry result: beforeState: keyPath: HKCU\DscExamples valueName: ManagedValue _exist: false afterState: keyPath: HKCU\DscExamples valueName: ManagedValue valueData: String: Default changedProperties: - valueData - _exist messages: [] hadErrors: false ``` -------------------------------- ### Example: Get Registry Resource Instance from Stdin Source: https://github.com/powershell/dsc/blob/main/docs/reference/cli/resource/get.md Retrieves the actual state of the Microsoft.Windows/Registry resource by piping instance properties as a JSON string to standard input. ```powershell '{ "keyPath": "HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion", "valueName": "SystemRoot" }' | dsc resource get --resource Microsoft.Windows/Registry --file - ``` ```yaml actualState: $id: https://developer.microsoft.com/json-schemas/windows/registry/20230303/Microsoft.Windows.Registry.schema.json keyPath: HKLM\Software\Microsoft\Windows NT\CurrentVersion valueName: SystemRoot valueData: String: C:\WINDOWS ``` -------------------------------- ### Example DSC Resource Adapter Configuration (Microsoft.DSC/PowerShell) Source: https://github.com/powershell/dsc/blob/main/docs/reference/schemas/resource/manifest/adapter.md An example demonstrating the 'adapter' property for the Microsoft.DSC/PowerShell DSC Resource Adapter. It shows how to configure the executable, arguments, and the expected configuration format ('full'). ```json "adapter": { "list": { "executable": "pwsh", "args": [ "-NoLogo", "-NonInteractive", "-NoProfile", "-Command", "./powershell.resource.ps1 List" ] }, "config": "full" } ``` -------------------------------- ### Example: Setting a resource with properties from stdin Source: https://github.com/powershell/dsc/blob/main/docs/reference/cli/resource/set.md Ensures the 'Example' key exists in the current user hive by passing the desired state as JSON from stdin to the `dsc resource set` command. ```powershell '{ "keyPath": "HKCU\\Example", "_exist": true }' | dsc resource set --resource Microsoft.Windows/Registry --file - ``` -------------------------------- ### Example: Get Registry Resource Instance with JSON Input Source: https://github.com/powershell/dsc/blob/main/docs/reference/cli/resource/get.md Retrieves the actual state of the Microsoft.Windows/Registry resource by providing instance properties as a JSON string via the --input option. ```powershell dsc resource get --resource Microsoft.Windows/Registry --input '{ "keyPath": "HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion", "valueName": "SystemRoot" }' ``` ```yaml actualState: $id: https://developer.microsoft.com/json-schemas/windows/registry/20230303/Microsoft.Windows.Registry.schema.json keyPath: HKLM\Software\Microsoft\Windows NT\CurrentVersion valueName: SystemRoot valueData: String: C:\WINDOWS ``` -------------------------------- ### Example: Get Registry Resource Instance from YAML File Source: https://github.com/powershell/dsc/blob/main/docs/reference/cli/resource/get.md Retrieves the actual state of the Microsoft.Windows/Registry resource by specifying instance properties in a YAML file using the --path option. ```yaml # ./example.yaml keyPath: HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion valueName: SystemRoot ``` ```powershell dsc resource get --resource Microsoft.Windows/Registry --path ./example.yaml ``` ```yaml actualState: $id: https://developer.microsoft.com/json-schemas/windows/registry/20230303/Microsoft.Windows.Registry.schema.json keyPath: HKLM\Software\Microsoft\Windows NT\CurrentVersion valueName: SystemRoot valueData: String: C:\WINDOWS ``` -------------------------------- ### Instance Definition Syntax Source: https://github.com/powershell/dsc/blob/main/docs/reference/resources/Microsoft/Windows/WMI/index.md Illustrates the syntax for defining WMI instances within a DSC configuration document. It covers both older and newer versions of DSC syntax for resource definition. ```yaml resources: - name: type: Microsoft.Windows/WMI properties: # Required properties resources: - name: type: / properties: # adapted resource properties # Or from v3.1.0-preview.2 onwards resources: - name: type: / properties: # adapted resource properties ``` -------------------------------- ### Verify Package Installation After Set Source: https://github.com/powershell/dsc/blob/main/docs/reference/resources/DSC/PackageManagement/Brew/examples/install-a-package-with-brew.md Tests the package installation again after using 'dsc resource set' to confirm the package now exists and is in the desired state. ```bash dsc resource test --resource DSC.PackageManagement/Brew --input '{"packageName":"node"}' ``` ```yaml desiredState: packageName: node actualState: _exist: true packageName: node version: "24.3.0" inDesiredState: true differingProperties: [] ``` -------------------------------- ### DSC Service Get Operation Result Source: https://github.com/powershell/dsc/blob/main/docs/reference/resources/Microsoft/Windows/WindowsPowerShell/examples/manage-a-windows-service.md The output from the `dsc resource get` command, showing the 'actualState' of the 'Spooler' service. This confirms the service is currently stopped and configured to start manually. ```yaml actualState: Status: null Description: This service spools print jobs and handles interaction with the printer. If you turn off this service, you won't be able to print or see your printers. DisplayName: Print Spooler ResourceId: null PsDscRunAsCredential: null Name: Spooler Credential: null PSComputerName: localhost ConfigurationName: null Ensure: null DependsOn: null SourceInfo: null BuiltInAccount: LocalSystem StartupType: Manual State: Stopped ModuleVersion: '1.1' ModuleName: PSDesiredStateConfiguration Path: C:\WINDOWS\System32\spoolsv.exe Dependencies: - RPCSS - http ``` -------------------------------- ### Get Array Length using DSC Source: https://github.com/powershell/dsc/blob/main/docs/reference/schemas/config/functions/length.md Demonstrates how to use the 'length()' function to get the number of elements in DSC arrays. It shows examples with arrays of different sizes, including an empty one. ```yaml $schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json parameters: smallArray: type: array defaultValue: - dsc - v3 largeArray: type: array defaultValue: - red - green - blue - yellow - purple emptyArray: type: array defaultValue: [] resources: - name: Check array lengths type: Microsoft.DSC.Debug/Echo properties: output: smallLength: "[length(parameters('smallArray'))]" largeLength: "[length(parameters('largeArray'))]" emptyLength: "[length(parameters('emptyArray'))]" ``` ```bash dsc config get --file length.example.1.dsc.config.yaml ``` -------------------------------- ### Incomplete Expression Source: https://github.com/powershell/dsc/blob/main/tree-sitter-dscexpression/test/corpus/invalid_expressions.txt Illustrates a parsing error where an expression starts with a bracket but is not properly closed. ```powershell [functionOne() ``` -------------------------------- ### DSC PackageManagement Apt Resource Source: https://github.com/powershell/dsc/blob/main/docs/prerelease-changelog.md The DSC.PackageManagement/Apt resource manages software on APT-based systems. It supports installing the latest version, uninstalling, getting current state, and exporting installed packages as DSC resource instances. ```powershell Install-DscPackage -Name Uninstall-DscPackage -Name Get-DscPackage -Name Export-DscPackage -Name ``` -------------------------------- ### DSC Get Result for 32-bit macOS Source: https://github.com/powershell/dsc/blob/main/docs/reference/resources/Microsoft/OSInfo/examples/validate-in-a-configuration.md Example output from 'dsc config get' on a 32-bit macOS system, showing the OSInfo resource's actual state and indicating it's out of the desired state. ```yaml metadata: Microsoft.DSC: version: 3.0.0 operation: get executionType: actual startDatetime: 2025-03-07T13:32:15.787101400-06:00 endDatetime: 2025-03-07T13:32:19.077737200-06:00 duration: PT3.2906358S securityContext: restricted results: - metadata: Microsoft.DSC: duration: PT2.5803652S name: Operating System Assertion type: Microsoft.DSC/Assertion result: - name: Is64BitOS type: Microsoft/OSInfo result: actualState: $id: https://developer.microsoft.com/json-schemas/dsc/os_info/20230303/Microsoft.Dsc.OS_Info.schema.json family: MacOS version: 13.5.0 bitness: '32' architecture: arm messages: [] hadErrors: false ``` -------------------------------- ### DSC Get Result for 64-bit Linux Source: https://github.com/powershell/dsc/blob/main/docs/reference/resources/Microsoft/OSInfo/examples/validate-in-a-configuration.md Example output from 'dsc config get' on a 64-bit Linux system, showing the OSInfo resource's actual state and indicating it's in the desired state. ```yaml metadata: Microsoft.DSC: version: 3.0.0 operation: get executionType: actual startDatetime: 2025-03-07T13:32:15.787101400-06:00 endDatetime: 2025-03-07T13:32:19.077737200-06:00 duration: PT3.2906358S securityContext: restricted results: - metadata: Microsoft.DSC: duration: PT2.5803652S name: Operating System Assertion type: Microsoft.DSC/Assertion result: - name: Is64BitOS type: Microsoft/OSInfo result: actualState: $id: https://developer.microsoft.com/json-schemas/dsc/os_info/20230303/Microsoft.Dsc.OS_Info.schema.json family: Linux version: '20.04' codename: focal bitness: '64' architecture: x86_64 messages: [] hadErrors: false ``` -------------------------------- ### DSC Config Set Example: Set Resource Instances Source: https://github.com/powershell/dsc/blob/main/docs/reference/cli/config/set.md An example of setting resource instances to their desired state using a YAML configuration file passed via standard input. ```yaml # example.dsc.config.yaml $schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json resources: - name: Windows only type: Microsoft.DSC/Assertion properties: $schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json resources: - name: os type: Microsoft/OSInfo properties: family: Windows - name: Current user registry example type: Microsoft.Windows/Registry properties: keyPath: HKCU\example _exist: true dependsOn: - "[resourceId('Microsoft.DSC/Assertion', 'Windows only')]" ``` ```powershell cat ./example.dsc.config.yaml | dsc config set --file - ``` -------------------------------- ### DSC Get Result for 32-bit Linux Source: https://github.com/powershell/dsc/blob/main/docs/reference/resources/Microsoft/OSInfo/examples/validate-in-a-configuration.md Example output from 'dsc config get' on a 32-bit Linux system, showing the OSInfo resource's actual state and indicating it's out of the desired state. ```yaml metadata: Microsoft.DSC: version: 3.0.0 operation: get executionType: actual startDatetime: 2025-03-07T13:32:15.787101400-06:00 endDatetime: 2025-03-07T13:32:19.077737200-06:00 duration: PT3.2906358S securityContext: restricted results: - metadata: Microsoft.DSC: duration: PT2.5803652S name: Operating System Assertion type: Microsoft.DSC/Assertion result: - name: Is64BitOS type: Microsoft/OSInfo result: actualState: $id: https://developer.microsoft.com/json-schemas/dsc/os_info/20230303/Microsoft.Dsc.OS_Info.schema.json family: Linux version: '20.04' codename: focal bitness: '32' architecture: i386 messages: [] hadErrors: false ``` -------------------------------- ### JSON input argument example Source: https://github.com/powershell/dsc/blob/main/docs/reference/schemas/resource/manifest/get.md Shows how to use a JSON input argument to pass data to the resource command. This example defines the 'executable', 'args' with a 'jsonInputArg', and specifies 'mandatory' for the JSON input. ```json "get": { "executable": "tstoy", "args": [ "config", "get", { "jsonInputArg": "--input", "mandatory": true } ] } ```