Skip to content

Passing object properties to Hashtable of class-based PowerShell resource #709

Closed
@JohnMcPMS

Description

@JohnMcPMS

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest version
  • Search the existing issues.

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, as config 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

  1. With this file:
# config.yaml

Action: Partial
Settings:
  experimentalFeatures:
    dsc3: true
  1. Install the Microsoft.WinGet.DSC module from PSGallery. This is the target resource class.
[DSCResource()]
class WinGetUserSettings
{
    # We need a key. Do not set.
    [DscProperty(Key)]
    [string]$SID

    # A hash table with the desired settings.
    [DscProperty(Mandatory)]
    [Hashtable]$Settings

    [DscProperty()]
    [WinGetAction]$Action = [WinGetAction]::Full
  1. Run the command:
> dsc.exe resource test -r Microsoft.WinGet.DSC/WinGetUserSettings -f config.yml

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

Name                           Value
----                           -----
PSVersion                      7.5.0
PSEdition                      Core
GitCommitId                    7.5.0
OS                             Microsoft Windows 10.0.23828
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Version

3.0.0

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions