Skip to content

Is there a way to access the unenumerated argument in [ValidateScript()]? #6185

@alx9r

Description

@alx9r

It appears that [ValidateScript()] performs conditional enumeration on the argument before invoking the validation script. Is there a way to access the unenumerated argument from the validation script?

Steps to reproduce

function f {
    param
    (
        [ValidateScript({($_[0] -eq 1) -and ($_[1] -eq 2)})]$x
    )
    'success'
}

f -x 1,2

Expected behavior

success

Actual behavior

f : Cannot validate argument on parameter 'x'. The "($_[0] -eq 1) -and ($_[1] -e
q 2)" validation script for the argument with value "1" did not return a result
of True. Determine why the validation script failed, and then try the command ag
ain.
At C:\test.ps1:9 char:6
+ f -x 1,2
+      ~~~
+ CategoryInfo          : InvalidData: (:) [f], ParameterBindingValidationExcept
ion
+ FullyQualifiedErrorId : ParameterArgumentValidationError,f

Environment data

> $PSVersionTable

Name                           Value                                            
----                           -----                                            
PSVersion                      6.0.0                                            
PSEdition                      Core                                             
GitCommitId                    v6.0.0                                           
OS                             Microsoft Windows 6.3.9600                       
Platform                       Win32NT                                          
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                          
PSRemotingProtocolVersion      2.3                                              
SerializationVersion           1.1.0.1                                          
WSManStackVersion              3.0                                              

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-No ActivityIssue has had no activity for 6 months or moreWG-Languageparser, language semantics

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions