---
title: "Ensure DSC Resource"
---
Ensures the configuration of a specified PowerShell DSC Resource.
Ensure-DscResource(
[ConfigurationKey: <text>],
Name: <text>,
[Module: <text>],
[Properties: <%(key1: value1, ...)>],
[PreferWindowsPowerShell: <text>]
);
This operation may be prefixed with PowerShell::
, although this is a built-in namespace and isn't really necessary.
Name | Format | Script Usage | Usage Notes |
---|---|---|---|
Otter configuration key | text | ConfigurationKey | The name of the DSC property which will be used as the Otter configuration key for the server. If this is not specified, the "Name" property is used. Default value is "Name". |
☆ Resource | text | Name | Value note: "ex: File". This argument is required. |
Module | text | Module | Default value is "PSDesiredStateConfiguration". |
Properties | %(key1: value1, ...) | Properties | DSC property hashtable as an OtterScript map. Example: %(DestinationPath: C:\hdars\1000.txt, Contents: test file ensured). Value note: "%(...)". |
Prefer Windows PowerShell | text | PreferWindowsPowerShell | When true, the script will be run using Windows PowerShell 5.1 where available. When false or on Linux (or on Windows systems without PowerShell 5.1 installed), the script will be run using PowerShell Core instead. Default value is "$PreferWindowsPowerShell". |
Note: An argument may be explicitly converted to an integral type by prefixing the value with [type::<typeName>], where <typeName> is one of: int, uint, long, ulong, double, decimal. Normally this conversion is performed automatically and this is not necessary.
# ensures the existence of a file on the server
Ensure-DscResource(
Name: File,
ConfigurationKey: DestinationPath,
Properties: %(
DestinationPath: C:\hdars\1000.txt,
Contents: test file ensured)
);
# runs a custom resource
Ensure-DscResource(
Name: cHdars,
Module: cHdarsResource,
ConfigurationKey: LocalServer,
Properties: %(
MaximumSessionLength: 1000,
PortsToListen: @(3322,4431,1123),
Enabled: true)
);