salt.states.win_dsc_resource#

State module for managing Windows PowerShell DSC Resources via Invoke-DscResource.

This module manages individual DSC resources without compiling a MOF file or involving the Local Configuration Manager (LCM). Salt controls the idempotency: it calls the resource's Test method first, and only calls Set if a change is needed.

Use the psget module to install DSC resource modules from the PowerShell Gallery before referencing them in states.

Example:

ensure_web_server:
  dsc_resource.managed:
    - name: WindowsFeature
    - module_name: PSDesiredStateConfiguration
    - properties:
        Name: Web-Server
        Ensure: Present

remove_telnet:
  dsc_resource.managed:
    - name: WindowsFeature
    - module_name: PSDesiredStateConfiguration
    - properties:
        Name: Telnet-Client
        Ensure: Absent

create_config_file:
  dsc_resource.managed:
    - name: File
    - module_name: PSDesiredStateConfiguration
    - properties:
        DestinationPath: C:\App\config.txt
        Ensure: Present
        Contents: managed by Salt

New in version 3008.1.

salt.states.win_dsc_resource.managed(name, module_name, properties)#

Ensure a DSC resource is in the desired state.

Calls dsc_resource.test to check whether changes are needed. If the resource is already in the desired state, returns immediately with no changes. Otherwise calls dsc_resource.set to apply the configuration, then verifies the result with another dsc_resource.test call.

The changes dictionary uses the actual before and after values returned by dsc_resource.get, giving a real diff of the resource properties.

Parameters:
  • name (str) -- The name of the DSC resource to manage, for example WindowsFeature or File. This also serves as the state ID. Required.

  • module_name (str) -- The name of the PowerShell module that contains the resource. For built-in resources use PSDesiredStateConfiguration. Required.

  • properties (dict) -- A dictionary of the desired resource properties. The required and optional keys vary by DSC resource. Required.

Returns:

A standard Salt state return with name, result, changes, and comment keys.

result values:

  • True — no changes were needed, or changes were applied successfully.

  • None — running in test mode and changes would be made.

  • False — an error occurred or changes could not be verified.

Return type:

dict

CLI Example:

install_iis:
  dsc_resource.managed:
    - name: WindowsFeature
    - module_name: PSDesiredStateConfiguration
    - properties:
        Name: Web-Server
        Ensure: Present
write_hosts_entry:
  dsc_resource.managed:
    - name: File
    - module_name: PSDesiredStateConfiguration
    - properties:
        DestinationPath: C:\\Temp\\hello.txt
        Ensure: Present
        Contents: Hello from Salt

New in version 3008.1.