Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
description: DSC examples are present
ms.date: 06/28/2023
ms.date: 06/03/2026
ms.topic: reference
title: DSCDscExamplesPresent
---
Expand All @@ -10,31 +10,29 @@ title: DSCDscExamplesPresent

## Description

Checks that DSC examples for given resource are present.
This rule detects if Desired State Configuration (DSC) examples for a given resource are present.

## How
To fix a violation of this rule, you must ensure that the `Examples` directory exists for:

To fix a violation of this rule, please make sure `Examples` directory is present:
- Non-class based resources, it should be at the same folder level as the `DSCResources` folder.
- Class based resources, it should be at the same folder level as the resource's `.psm1` file.

- For non-class based resources it should exist at the same folder level as `DSCResources` folder.
- For class based resources it should be present at the same folder level as resource `.psm1` file.

The `Examples` folder should contain a sample configuration for given resource. The filename should
contain the resource's name.
The `Examples` folder must contain a sample configuration for the resource. The filename should
include the resource's name.

## Example

### Non-class based resource

Let's assume we have non-class based resource with a following file structure:
Let's assume we have non-class based resource with the following file structure:

- xAzure
- DSCResources
- MSFT_xAzureSubscription
- MSFT_xAzureSubscription.psm1
- MSFT_xAzureSubscription.schema.mof

In this case, to fix this warning, we should add examples in a following way:
In this case, to fix this warning, add examples in the following way:

- xAzure
- DSCResources
Expand All @@ -47,13 +45,13 @@ In this case, to fix this warning, we should add examples in a following way:

### Class based resource

Let's assume we have class based resource with a following file structure:
Let's assume we have class based resource with the following file structure:

- MyDscResource
- MyDscResource.psm1
- MyDscResource.psd1

In this case, to fix this warning, we should add examples in a following way:
In this case, to fix this warning, add examples in the following way:

- MyDscResource
- MyDscResource.psm1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
description: Dsc tests are present
ms.date: 06/28/2023
description: DSC tests are present
ms.date: 06/03/2026
ms.topic: reference
title: DSCDscTestsPresent
---
Expand All @@ -10,31 +10,30 @@ title: DSCDscTestsPresent

## Description

Checks that DSC tests for given resource are present.
This rule detects if Desired State Configuration (DSC) tests for a given resource are present.

## How
To fix a violation of this rule, you must ensure that the `Tests` directory is present for:

To fix a violation of this rule, please make sure `Tests` directory is present:
- Non-class based resources, it should exist at the same folder level as the `DSCResources`
folder.
- Class based resources, it should be at the same folder level as the resource's `.psm1` file.

- For non-class based resources it should exist at the same folder level as `DSCResources` folder.
- For class based resources it should be present at the same folder level as resource `.psm1` file.

The `Tests` folder should contain test script for given resource. The filename should contain the
resource's name.
The `Tests` folder must contain a test script for the given resource. The filename should include
the resource's name.

## Example

### Non-class based resource

Let's assume we have non-class based resource with a following file structure:
Let's assume we have non-class based resource with the following file structure:

- xAzure
- DSCResources
- MSFT_xAzureSubscription
- MSFT_xAzureSubscription.psm1
- MSFT_xAzureSubscription.schema.mof

In this case, to fix this warning, we should add tests in a following way:
In this case, to fix this warning, add tests in the following way:

- xAzure
- DSCResources
Expand All @@ -46,13 +45,13 @@ In this case, to fix this warning, we should add tests in a following way:

### Class based resource

Let's assume we have class based resource with a following file structure:
Let's assume we have class based resource with the following file structure:

- MyDscResource
- MyDscResource.psm1
- MyDscResource.psd1

In this case, to fix this warning, we should add tests in a following way:
In this case, to fix this warning, add tests in the following way:

- MyDscResource
- MyDscResource.psm1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
description: Return Correct Types For DSC Functions
ms.date: 06/28/2023
description: Return correct types for DSC functions
ms.date: 06/03/2026
ms.topic: reference
title: DSCReturnCorrectTypesForDSCFunctions
---
Expand All @@ -10,27 +10,24 @@ title: DSCReturnCorrectTypesForDSCFunctions

## Description

The functions in DSC resources have specific return objects.
This rule detects if functions in Desired State Configuration (DSC) resources have specific return
objects. You'll need to ensure that each function returns the correct type.

For non-class based resources:

- `Get-TargetResource` must return a hash table.
- `Set-TargetResource` must not return any value.
- `Test-TargetResource` must return a boolean.
- `Get-TargetResource` must return a hash table.

For class based resources:

- `Get` must return an instance of the DSC class.
- `Set` must not return any value.
- `Test` must return a boolean.
- `Get` must return an instance of the DSC class.

## How

Ensure that each function returns the correct type.

## Example 1
## Example

### Wrong
### Noncompliant MOF-based resource

```powershell
function Get-TargetResource
Expand Down Expand Up @@ -67,7 +64,7 @@ function Test-TargetResource
}
```

### Correct
### Compliant MOF-based resource

```powershell
function Get-TargetResource
Expand Down Expand Up @@ -106,9 +103,7 @@ function Test-TargetResource
}
```

## Example 2

### Wrong
### Noncompliant class-based resource

```powershell
[DscResource()]
Expand All @@ -117,12 +112,7 @@ class MyDSCResource
[DscProperty(Key)]
[string] $Name

[String] Get()
{
...
}

[String] Set()
[void] Set()
{
...
}
Expand All @@ -134,7 +124,7 @@ class MyDSCResource
}
```

### Correct
### Compliant class-based resource

```powershell
[DscResource()]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
description: Use Standard Get/Set/Test TargetResource functions in DSC Resource
ms.date: 06/28/2023
description: Use standard DSC Get, Set, and Test TargetResource functions in a resource
ms.date: 06/03/2026
ms.topic: reference
title: DSCStandardDSCFunctionsInResource
---
Expand All @@ -10,27 +10,24 @@ title: DSCStandardDSCFunctionsInResource

## Description

All DSC resources are required to implement the correct functions.
This rule detects if all Desired State Configuration (DSC) resources implement the correct
functions. Add the missing functions to the resource.

For non-class based resources:

- `Get-TargetResource`
- `Set-TargetResource`
- `Test-TargetResource`
- `Get-TargetResource`

For class based resources:

- `Get`
- `Set`
- `Test`
- `Get`

## How

Add the missing functions to the resource.

## Example 1
## Example

### Wrong
### Noncompliant MOF-based resource

```powershell
function Get-TargetResource
Expand All @@ -45,8 +42,9 @@ function Get-TargetResource
...
}

function Set-TargetResource
function Test-TargetResource
{
[OutputType([System.Boolean])]
param
(
[parameter(Mandatory = $true)]
Expand All @@ -57,7 +55,7 @@ function Set-TargetResource
}
```

### Correct
### Compliant MOF-based resource

```powershell
function Get-TargetResource
Expand Down Expand Up @@ -96,9 +94,7 @@ function Test-TargetResource
}
```

## Example 2

### Wrong
### Noncompliant class-based resource

```powershell
[DscResource()]
Expand All @@ -117,8 +113,9 @@ class MyDSCResource
...
}
}
```

### Correct
### Compliant class-based resource

```powershell
[DscResource()]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
description: Use identical mandatory parameters for DSC Get/Test/Set TargetResource functions
ms.date: 06/28/2023
description: Use identical mandatory parameters for DSC Get, Set, and Test TargetResource functions in a resource
ms.date: 06/03/2026
ms.topic: reference
title: DSCUseIdenticalMandatoryParametersForDSC
---
Expand All @@ -10,20 +10,19 @@ title: DSCUseIdenticalMandatoryParametersForDSC

## Description

For script based DSC resources, if a property is declared with attributes `Key` of `Required` in a
mof file, then is should be present as a mandatory parameter in the corresponding
`Get-TargetResource`, `Set-TargetResource` and `Test-TargetResource` functions.
This rule detects if MOF-based Desired State Configuration (DSC) resources have properties
declared with `Key` or `Required` attributes in a `.mof` file that aren't present as mandatory
parameters in the corresponding functions. These properties must be declared as mandatory
parameters in the `Get-TargetResource`, `Set-TargetResource`, and `Test-TargetResource` functions.

## How

Make sure all the properties with `Key` and `Required` attributes have equivalent mandatory
parameters in the `Get/Set/Test` functions.
All properties with `Key` and `Required` attributes should have matching mandatory
parameters in the **Get**, **Set**, and **Test** functions.

## Example

Consider the following `mof` file.
Consider the following MOF schema file.

```powershell
```mof
class WaitForAny : OMI_BaseResource
{
[key, Description("Name of Resource on remote machine")]
Expand All @@ -34,7 +33,7 @@ class WaitForAny : OMI_BaseResource
};
```

### Wrong
### Noncompliant

```powershell
function Get-TargetResource
Expand Down Expand Up @@ -74,7 +73,7 @@ function Test-TargetResource
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[String]
$Message,
$Message

[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
Expand All @@ -84,7 +83,7 @@ function Test-TargetResource
}
```

### Correct
### Compliant

```powershell
function Get-TargetResource
Expand Down
Loading
Loading