PowerShell Creating DSC Class-Based Resources

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Introduction

Starting with PowerShell version 5.0, you can use PowerShell class definitions to create Desired State Configuration (DSC) Resources.

To aid in building DSC Resource, there's a [DscResource()] attribute that's applied to the class definition, and a [DscProperty()] resource to designate properties as configurable by the DSC Resource user.

Remarks

A class-based DSC Resource must:

  • Be decorated with the [DscResource()] attribute
  • Define a Test() method that returns [bool]
  • Define a Get() method that returns its own object type (eg. [Ticket])
  • Define a Set() method that returns [void]
  • At least one Key DSC Property

After creating a class-based PowerShell DSC Resource, it must be "exported" from a module, using a module manifest (.psd1) file. Within the module manifest, the DscResourcesToExport hashtable key is used to declare an array of DSC Resources (class names) to "export" from the module. This enables consumers of the DSC module to "see" the class-based resources inside the module.



Got any PowerShell Question?