Skip to content

PSDSCAdapter cannot process argument transformation #487

@Gijsreyn

Description

@Gijsreyn

Prerequisites

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

Summary

I am experience a strange problem whenever I tried executing the Microsoft.DSC/PowerShell resource. I have the following file winget_dsc.config.yml modified from the examples:

$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
parameters:
    ensure:
        type: string
        defaultValue: Present
        allowedValues:
            - Present
            - Absent
resources:
    - name: Use class PowerShell resources
      type: Microsoft.DSC/PowerShell
      properties:
          resources:
              - name: PowerShell 7 Preview
                type: Microsoft.WinGet.DSC/WinGetPackage
                properties:
                    Id: Microsoft.PowerShell.Preview
                    Ensure: "[parameters('ensure')]"

When I execute it, I get the following error message:

image

Steps to reproduce

  1. Use Install-Module -Name Microsoft.WinGet.DSC -Scope AllUsers and Install-PSResource -Name Microsoft.WinGet.DSC -Scope AllUsers
  2. Create the YAML configuration file in the description above
  3. Execute dsc config set --path winget_dsc.config.yaml

Expected behavior

I would have expected the cache refreshing to filter out the latest DSC module it tries to return in the following lines:


foreach ($member in $typeDefinitionAst.Members) {
    $property = $member -as [System.Management.Automation.Language.PropertyMemberAst]
    if (($property -eq $null) -or ($property.IsStatic)) {
        continue;
    }
    $skipProperty = $true
    $isKeyProperty = $false
    foreach ($attr in $property.Attributes) {
        if ($attr.TypeName.Name -eq 'DscProperty') {
            $skipProperty = $false
            foreach ($attrArg in $attr.NamedArguments) {
                if ($attrArg.ArgumentName -eq 'Key') {
                    $isKeyProperty = $true
                }
            }
        }
    }
    if ($skipProperty) {
        continue;
    }

    [DscResourcePropertyInfo]$prop = [DscResourcePropertyInfo]::new()
    $prop.Name = $property.Name
    $prop.PropertyType = $property.PropertyType.TypeName.Name
    $prop.IsMandatory = $isKeyProperty 
    $DscResourceInfo.Properties.Add($prop)
}

$resourceList.Add($DscResourceInfo)

Actual behavior

Throws an error if multiple modules are available.

Error details

No response

Environment data

Name                           Value
----                           -----
PSVersion                      7.4.1
PSEdition                      Core
GitCommitId                    7.4.1
OS                             Microsoft Windows 10.0.19045
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-preview.8

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions