Skip to content

Files

Latest commit

 

History

History
136 lines (112 loc) · 1.96 KB

DSCStandardDSCFunctionsInResource.md

File metadata and controls

136 lines (112 loc) · 1.96 KB

Pattern: Missing standard function for DSC

Issue: -

Description

All DSC resources are required to implement the correct functions.

For non-class based resources:

  • Set-TargetResource
  • Test-TargetResource
  • Get-TargetResource

For class based resources:

  • Set
  • Test
  • Get

How

Add the missing functions to the resource.

Example of incorrect code:

function Get-TargetResource
{
    [OutputType([Hashtable])]
    param
    (
        [parameter(Mandatory = $true)]
        [String]
        $Name
    )
    ...
}

function Set-TargetResource
{
    param
    (
        [parameter(Mandatory = $true)]
        [String]
        $Name
    )
    ...
}

Example of correct code:

function Get-TargetResource
{
    [OutputType([Hashtable])]
    param
    (
        [parameter(Mandatory = $true)]
        [String]
        $Name
    )
    ...
}

function Set-TargetResource
{
    param
    (
        [parameter(Mandatory = $true)]
        [String]
        $Name
    )
    ...
}

function Test-TargetResource
{
    [OutputType([System.Boolean])]
    param
    (
        [parameter(Mandatory = $true)]
        [String]
        $Name
    )
    ...
}

Example of incorrect code:

[DscResource()]
class MyDSCResource
{
    [DscProperty(Key)]
    [string] $Name

    [void] Set()
    {
        ...
    }

    [bool] Test()
    {
        ...
    }
}

Example of **correct** code:

``` PowerShell
[DscResource()]
class MyDSCResource
{
    [DscProperty(Key)]
    [string] $Name

    [MyDSCResource] Get()
    {
        ...
    }

    [void] Set()
    {
        ...
    }

    [bool] Test()
    {
        ...
    }
}

Further Reading