salt.modules.win_dsc_resource#

Module for invoking individual PowerShell DSC Resources directly using Invoke-DscResource.

This module allows Salt to apply, test, and retrieve the state of any installed PowerShell DSC resource without compiling a MOF file or involving the Local Configuration Manager (LCM).

Use the psget module to install DSC resource modules from the PowerShell Gallery before using them here.

New in version 3008.1.

depends:
  • pythonnet

  • PowerShell 5.0

salt.modules.win_dsc_resource.get(name, module_name, properties)#

Return the current state of a DSC resource by calling Invoke-DscResource -Method Get.

Parameters:
  • name (str) -- The name of the DSC resource to query. For example, WindowsFeature or File. 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 resource properties sufficient to identify the resource instance. The required keys vary by resource. Required.

Returns:

A dictionary of the resource's current property values as reported by the DSC resource's Get method.

Return type:

dict

Raises:

CLI Example:

salt '*' dsc_resource.get File PSDesiredStateConfiguration \
    properties="{'DestinationPath': 'C:\\Temp\\test.txt', 'Ensure': 'Present'}"
salt '*' dsc_resource.get WindowsFeature PSDesiredStateConfiguration \
    properties="{'Name': 'Web-Server', 'Ensure': 'Present'}"

New in version 3008.1.

salt.modules.win_dsc_resource.set_(name, module_name, properties)#

Apply a DSC resource to the desired state by calling Invoke-DscResource -Method Set.

Parameters:
  • name (str) -- The name of the DSC resource to apply. Required.

  • module_name (str) -- The name of the PowerShell module that contains the resource. Required.

  • properties (dict) -- A dictionary of the desired resource properties. Required.

Returns:

True if the resource was applied successfully.

Return type:

bool

Raises:

CLI Example:

salt '*' dsc_resource.set File PSDesiredStateConfiguration \
    properties="{'DestinationPath': 'C:\\Temp\\test.txt', 'Ensure': 'Present', 'Contents': 'hello'}"
salt '*' dsc_resource.set WindowsFeature PSDesiredStateConfiguration \
    properties="{'Name': 'Web-Server', 'Ensure': 'Present'}"

New in version 3008.1.

salt.modules.win_dsc_resource.test(name, module_name, properties)#

Test whether a DSC resource is in the desired state by calling Invoke-DscResource -Method Test.

Parameters:
  • name (str) -- The name of the DSC resource to test. Required.

  • module_name (str) -- The name of the PowerShell module that contains the resource. Required.

  • properties (dict) -- A dictionary of the desired resource properties. Required.

Returns:

True if the resource is already in the desired state, False if changes are needed.

Return type:

bool

Raises:

CLI Example:

salt '*' dsc_resource.test File PSDesiredStateConfiguration \
    properties="{'DestinationPath': 'C:\\Temp\\test.txt', 'Ensure': 'Present'}"
salt '*' dsc_resource.test WindowsFeature PSDesiredStateConfiguration \
    properties="{'Name': 'Web-Server', 'Ensure': 'Present'}"

New in version 3008.1.