PowerShell / Crescendo

a module for wrapping native applications in a PowerShell function and module
MIT License
397 stars 37 forks source link

Can't use "Value" as parameter name #174

Closed potatoqualitee closed 1 year ago

potatoqualitee commented 2 years ago

Prerequisites

Steps to reproduce

This works

    @{
        ParameterType                   = "decimal"
        Name                            = "NewValue"
        Description                     = "The new numerical value of the property"
        ValueFromPipeline               = $false
        ValueFromPipelineByPropertyName = $true
        Position                        = 1
        OriginalPosition                = 1
        ParameterSetName                = "Default"
    }

This does not


    @{
        ParameterType                   = "decimal"
        Name                            = "Value"
        Description                     = "The new numerical value of the property"
        ValueFromPipeline               = $false
        ValueFromPipelineByPropertyName = $true
        Position                        = 1
        OriginalPosition                = 1
        ParameterSetName                = "Default"
    }

This is what the output looks like

image

Expected behavior

I should be able to name my parameters the way I do when building a regular PowerShell module.

Actual behavior

Can't use `-Value`

Error details

No response

Environment data

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

Version

1.0.0

Visuals

No response

JamesWTruher commented 1 year ago

@potatoqualitee I'm not quite sure what's going on there, but the error isn't due the use of the parameter named Value. I was able to create a very simple example with a parameter named Value. Also, the error message is pretty clear - it's having trouble converting a switch to a decimal, which is confusing in itself. Would you be willing to share the offending configuration file?

potatoqualitee commented 1 year ago

Hey @JamesWTruher, This is where I used it in my own code. I ended up setting an alias to Value which worked for my needs.

https://github.com/potatoqualitee/pastel/blob/main/src/Edit-PastelColorProperty.ps1#L24

The error message is confusing to me because I can make it go away simply by renaming the variable.