當資源的Get-TargetResource
函數返回的哈希表中的值類型不匹配或無法隱式轉換爲資源的MOF中定義的類型時,會發生這種情況。
我的第一DSC資源的MOF聲明這個屬性:
[Write]
boolean CaseSensitive;
我Get-TargetResource
函數聲明一個Switch
參數:
[Switch]
# The INI file being modified is case-sensitive.
$CaseSensitive,
有人被退回像這樣:
return @{
# snip
CaseSensitive = $CaseSensitive;
}
解決方案是自己投擲開關:
return @{
# snip
CaseSensitive = [bool]$CaseSensitive;
}
我的第二個資源的MOF聲明一個PSCredential
屬性:
[Write,
EmbeddedInstance("MSFT_Credential")]
string TaskCredential;
我Get-TargetResource
函數聲明這個PsCredential
對象:
[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,
默認情況下,這個屬性是越來越返回一個空字符串:
$resource = @{
TaskCredential = '';
}
的解決方案是設置TaskCredential
的默認值,以$null
:
$resource = @{
TaskCredential = $null;
}