Skip to content

Latest commit

 

History

History
135 lines (109 loc) · 3.64 KB

Scripts.adoc

File metadata and controls

135 lines (109 loc) · 3.64 KB

DSC Resource 'Scripts'

Scripts provides a mechanism to run PowerShell script blocks on a target node.

Source

DSC Resource

Documentation

Table 1. Attributes of category 'Scripts'
Parameter Attribute DataType Description Allowed Values

Items

hashtable[]

The xScript DSC resource provides a mechanism to run PowerShell script blocks on a target node..

Table 2. Attributes of category 'Scripts/Items'
Parameter Attribute DataType Description Allowed Values

Name

Key

String

Script Name

Params

Hashtable[]

Optional script paramters as Key-Value hashtable

You can access these parameters with the variable $params in your script blocks.

GetScript

String

A string that can be used to create a PowerShell script block that retrieves the current state of the resource. This script block runs when the Get-DscConfiguration cmdlet is called. This script block should return a hash table containing one key named Result with a string value.

If the GetScript attribute is empty or missing a default script @{ Result = 'N/A' } is generated.

SetScript

String

A string that can be used to create a PowerShell script block that sets the resource to the desired state. This script block runs conditionally when the Start-DscConfiguration cmdlet is called. The TestScript script block will run first. If the TestScript block returns False, this script block will run. If the TestScript block returns True, this script block will not run. This script block should not return.

If the SetScript attribute is empty or missing a default script Write-Error 'SetScript is not implemented.' is generated and the resource is marked as not in the desired state.

TestScript

Mandatory

String

A string that can be used to create a PowerShell script block that validates whether or not the resource is in the desired state. This script block runs when the Start-DscConfiguration cmdlet is called or when the Test-DscConfiguration cmdlet is called. This script block should return a boolean with True meaning that the resource is in the desired state and False meaning that the resource is not in the desired state.

Credential

PSCredential

The credential of the user account to run the script under if needed.

Example
Scripts:
  Items:
  - Name: JeaDiscovery.psd1
    GetScript: |
      @{
        Result = (Get-Date)
      }
    TestScript: |
      [bool](Get-Date)
    SetScript: |
      Get-Date

  - Name: ParamTestScript
    Params:
      a: 1
      b: Test
      c:
        - x: 1
          y: 2
          z: 3
    TestScript: |
      Write-Verbose 'Param a:   ' + $params.a
      Write-Verbose 'Param c.x: ' + $params.c.x
      [bool](Get-Date)