This happens when a value's type in the hashtable returned by a resource's Get-TargetResource
function doesn't match or can't be implicitly converted to, the type defined in a resource's MOF.
My first DSC resource's MOF declares this property:
[Write]
boolean CaseSensitive;
My Get-TargetResource
function declares this a Switch
parameter:
[Switch]
# The INI file being modified is case-sensitive.
$CaseSensitive,
It was getting returned like this:
return @{
# snip
CaseSensitive = $CaseSensitive;
}
The solution was to cast the switch myself:
return @{
# snip
CaseSensitive = [bool]$CaseSensitive;
}
My second resource's MOF declares a PSCredential
property:
[Write,
EmbeddedInstance("MSFT_Credential")]
string TaskCredential;
My Get-TargetResource
function declares this a PsCredential
object:
[Management.Automation.PSCredential]
# The principal the task should run as. Use `Principal` parameter to run as a built-in security principal. Required if `Interactive` or `NoPassword` switches are used.
$TaskCredential,
By default, this property was getting returned as an empty string:
$resource = @{
TaskCredential = '';
}
The solution was to set TaskCredential
's default value to $null
:
$resource = @{
TaskCredential = $null;
}