-
Notifications
You must be signed in to change notification settings - Fork 34
Passing object properties to Hashtable of class-based PowerShell resource #709
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @JohnMcPMS. I think you found something interesting. I was trying to reproduce the config part, and what you probably did in the first place, was something like this: $schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
resources:
- name: UserSettings
type: Microsoft.WinGet.DSC/WinGetUserSettings
properties:
Action: 'Partial'
Settings:
experimentalFeatures:
dsc3: true This gives the error you reported, but it should have been: $schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
resources:
- name: Use class PowerShell resources
type: Microsoft.DSC/PowerShell
properties:
resources:
- name: PowerShell 7 Preview
type: Microsoft.WinGet.DSC/WinGetUserSettings
properties:
Action: Partial
Settings:
experimentalFeatures:
dsc3: true This gives the same error message as the if ($DesiredState.properties) {
# set each property of $dscResourceInstance to the value of the property in the $desiredState INPUT object
$DesiredState.properties.psobject.properties | ForEach-Object -Process {
$dscResourceInstance.$($_.Name) = $_.Value
}
} The if ($DesiredState.properties) {
# set each property of $dscResourceInstance to the value of the property in the $desiredState INPUT object
$DesiredState.properties.psobject.properties | ForEach-Object -Process {
if ($_.Value.GetType().Name -eq 'PSCustomObject') {
$hashTable = @{}
$_.Value.psobject.properties | ForEach-Object { $hashTable[$_.Name] = $_.Value }
$dscResourceInstance.$($_.Name) = $hashTable
}
else
{
Write-DscTrace -Message "Setting property: $($_.Name) to $($_.Value.TypeNameOfValue)"
$dscResourceInstance.$($_.Name) = $_.Value
}
}
} Then the result ends in what you're looking for: It however asks the fundamental question I guess: how does @SteveL-MSFT or @michaeltlombardi , what are your thoughts on? |
It was my understanding that the |
@JohnMcPMS the issue you are referring to is this #693 which I'm working on |
@Gijsreyn I think you are on the right track for a fix, can you create a PR with added test? |
This should be fixed by #713 |
Prerequisites
Summary
When passing an object type property to a resource that is using the
Microsoft.DSC/PowerShell
adapter, the object is not converted to a Hashtable correctly.This currently only affects the
resource
commands, asconfig
complains about custom resources before attempting to execute them (Not implemented: Custom resource not supported
). Not sure if that is a bug (resource
should also block) or simply a TODO.Steps to reproduce
Expected behavior
Resource invocation successful
Actual behavior
2025-03-17T18:13:16.530836Z ERROR PID 8308: Exception: Exception setting "Settings": "Cannot convert value "@{experimentalFeatures=}" to type "System.Collections.Hashtable". Error: "Cannot convert the "@{experimentalFeatures=}" value of type "System.Management.Automation.PSCustomObject" to type "System.Collections.Hashtable".""
Error details
Environment data
Version
3.0.0
Visuals
No response
The text was updated successfully, but these errors were encountered: