Skip to content

PSDSCAdapter cannot process argument transformation #487

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

Closed
3 tasks done
Gijsreyn opened this issue Jul 11, 2024 · 2 comments · Fixed by #489
Closed
3 tasks done

PSDSCAdapter cannot process argument transformation #487

Gijsreyn opened this issue Jul 11, 2024 · 2 comments · Fixed by #489
Labels
Issue-Bug Something isn't working Need-Review

Comments

@Gijsreyn
Copy link
Contributor

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

@Gijsreyn Gijsreyn added Issue-Bug Something isn't working Need-Review labels Jul 11, 2024
@anmenaga
Copy link

  1. I can't repro this exact error message; but I see in the cache that not the latest version is selected if there are several versions of the module installed; This probably needs to be fixed to use the latest version.
  2. How are you able to install Microsoft.WinGet.DSC module without -AllowPrerelease flag? At this moment looks like they have only -alpha versions on PSGallery...
  3. please rerun with -l trace (i.e. dsc -l trace config set --path winget_dsc.config.yaml) and share the output;
  4. please share the output of get-module -ListAvailable -Name Microsoft.WinGet.DSC | Format-List

@Gijsreyn
Copy link
Contributor Author

  1. I can't repro this exact error message; but I see in the cache that not the latest version is selected if there are several versions of the module installed; This probably needs to be fixed to use the latest version.

    1. How are you able to install Microsoft.WinGet.DSC module without -AllowPrerelease flag? At this moment looks like they have only -alpha versions on PSGallery...

    2. please rerun with -l trace (i.e. dsc -l trace config set --path winget_dsc.config.yaml) and share the output;

    3. please share the output of get-module -ListAvailable -Name Microsoft.WinGet.DSC | Format-List

Hi Andrew,

In the steps to reproduce section, I used both Install-Module -Name Microsoft.WinGet.DSC -Scope AllUsers on Windows PowerShell and Install-PSResource -Name Microsoft.WinGet.DSC -Scope AllUsers.

image

Hope that helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Bug Something isn't working Need-Review
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants