Prerequisites
Version
v1.1
Links
Summary
When a user wants to invoke a DSC Resource that has complex properties in PSDSCv1.1, they need to convert the complex property into a CimInstance or the invocation errors confusingly.
Details
With the example resource definition:
[DscResource()]
class InvocableExample {
[DscProperty(Key)] [string] $Path
[DscProperty()] [Complex] $Info
[DscProperty()] [VeryComplex] $Options
[InvocableExample] Get() { return $this }
[bool] Test() { return $true }
[void] Set() { }
}
class Complex {
[DscProperty()] [string] $Version
[DscProperty()] [bool] $StartOnBoot
}
class VeryComplex {
[DscProperty()] [string] $Name
[DscProperty()] [Nested[]] $Settings
}
class Nested {
[DscProperty()] [bool] $Enabled
[DscProperty()] [string] $Name
}
You can use New-CimInstance with the ClientOnly parameter to create the complex property inline for the DSC Resource's property hash:
Invoke-DscResource -Name InvocableExample -Method Get -ModuleName ExampleResources -Property @{
Path = 'C:\dsc\example.json'
Info = New-CimInstance -ClientOnly -ClassName Complex -Property @{
Version = '1.1.0'
}
}
When the property's type is an array, like [Nested[]], you need to cast the inline array to [CimInstance[]]:
$Options = New-CimInstance -ClientOnly -ClassName VeryComplex -Property @{
Name = 'Nested Options'
Settings = New-CimInstance -ClientOnly Nested -Property [CimInstance[]]@(
@{ Name = 'First' ; Enabled = $true }
@{ Name = 'Second' ; Enabled = $false }
)
}
You need to convert every complex property, including nested ones, with New-CimInstance.
Suggested Fix
Extend the documentation for invoking DSC Resources in v1.1 to document this requirement.
Prerequisites
Get-Foocmdlet" instead of "Typo."Version
v1.1
Links
Summary
When a user wants to invoke a DSC Resource that has complex properties in PSDSCv1.1, they need to convert the complex property into a CimInstance or the invocation errors confusingly.
Details
With the example resource definition:
You can use
New-CimInstancewith the ClientOnly parameter to create the complex property inline for the DSC Resource's property hash:When the property's type is an array, like
[Nested[]], you need to cast the inline array to[CimInstance[]]:You need to convert every complex property, including nested ones, with
New-CimInstance.Suggested Fix
Extend the documentation for invoking DSC Resources in v1.1 to document this requirement.