Udostępnij przez


StandardDSCFunctionsInResource

Poziom ważności: błąd

Opis

Wszystkie zasoby DSC są wymagane do zaimplementowania prawidłowych funkcji.

W przypadku zasobów nieklasowych:

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

W przypadku zasobów opartych na klasach:

  • Set
  • Test
  • Get

Jak

Dodaj brakujące funkcje do zasobu.

Przykład 1

Nieodpowiednim

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

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

Odpowiedź prawidłowa

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
    )
    ...
}

Przykład 2

Nieodpowiednim

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

    [void] Set()
    {
        ...
    }

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

### Correct

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

    [MyDSCResource] Get()
    {
        ...
    }

    [void] Set()
    {
        ...
    }

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