12.9 C
New York
Tuesday, May 20, 2025

Using Desired State Configuration (DSC) v3 on Windows Server 2025


Microsoft Desired State Configuration v3 has some substantive changes compared to previous versions of the technology. Unlike PowerShell Desired State Configuration (PSDSC) v1.1 and v2, DSC v3 operates as a standalone command rather than a service, eliminating the need for a local configuration manager. This architectural change makes DSC v3 easier to use and scale, allowing any tool that can execute commands on Windows Server, such as Scheduled Tasks, to apply DSC configurations.

For this document:

  • DSC refers to Desired State Configuration v3.0.0
  • PSDSC refers to PowerShell Desired State Configuration (PSDSC) v1.1 and v2

You can install DSC using WinGet. Windows Server 2025 includes built-in support for WinGet, making the installation process more straightforward than on previous server versions. However, it’s important to note that winget is only available for Windows Server 2025 with Desktop Experience and can’t be used with Server Core deployments.

DSC v3 requires PowerShell 7.2 or later. As Windows Server 2025 comes with Windows PowerShell 5.1, you’ll need to install PowerShell 7.x separately, which you can do manually or using WinGet from an elevated PowerShell session.

winget install microsoft.powershell

The PSDesiredStateConfiguration module specifies a minimum PowerShell version of 7.2 in its module manifest.

WinGet provides the most straightforward installation experience with automatic updates:

  1. Open PowerShell with administrative privileges
  2. Search for the DSC package using:
winget search DesiredStateConfiguration

  1. Install the stable version using:
winget install --id 9NVTPZWRC6KQ --source msstore

Alternatively, download the latest release from the PowerShell/DSC repository and add the folder containing the expanded archive contents to your PATH environment variable.

Basic DSC v3 Commands

To view all available commands in DSC v3, use:

dsc --help

The output will display available commands including:

  • completer – Generate a shell completion script
  • config – Apply a configuration document
  • resource – Invoke a specific DSC resource
  • schema – Get the JSON schema for a DSC type
  • help – Display help information for commands

To see the resources available for use in configurations:

dsc resource list

This command displays all DSC resources installed on your system that can be used in configuration documents.

Creating DSC v3 Configurations

DSC v3 configurations can be written in YAML format, which is more concise and readable than the MOF format used in previous versions.

A DSC v3 configuration document must include:

  1. A reference to the DSC resource schema
  2. At least one resource definition with properties

Creating a Basic Configuration

Here’s an example of a basic configuration in YAML format:

$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/08/config/document.json
resources:
  - name: Force icon view in Control Panel
    type: Microsoft.Windows/Registry
    properties:
      keyPath: HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer\
      valueName: ForceClassicControlPanel
      valueData:
        DWord: 1

This configuration sets a registry value to force the Control Panel to display using the classic icon view.

For compatibility with classic PowerShell resources, you can use the WindowsPowerShell resource type:

$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
metadata:
  name: IIS-Configuration
resources:
  - name: Use Windows PowerShell resources
    type: Microsoft.Windows/WindowsPowerShell
    properties:
      resources:
        - name: Web server install
          type: PSDesiredStateConfiguration/WindowsFeature
          properties:
            Name: Web-Server
            Ensure: Present

This configuration uses the classic WindowsFeature resource from the PSDesiredStateConfiguration module to install IIS.

Once you’ve created a configuration document, you can test and apply it using DSC v3 commands.

To test a configuration to see what changes would be made (rather than shouting Cowabunga on production systems) run the following command:

dsc config get -f .\iis-config.yaml

This command assesses the current state without making changes, showing what would happen if you applied the configuration.

To apply a configuration run a version of the command (with your yaml file specified):

dsc config set -f .\iis-config.yaml

This command applies the configuration defined in the YAML file to your system.

You can find out more about DSC v3 at the following locations:

https://devblogs.microsoft.com/powershell/get-started-with-dsc-v3/     

https://github.com/PowerShell/PSDesiredStateConfiguration

https://learn.microsoft.com/powershell/dsc/overview?view=dsc-3.0&preserveView=true    

https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-windows?view=powershell-7.5 

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles