Please feel free to provide feedback or file bugs here.

Parameter validation

Votes from Connect: 5

Original Date Submitted: 2/6/2015 3:54:49 PM

Description:
********Contact Information********
Handle: edi89
Site Name: PowerShell
Feedback ID: 1117495
***************************************

Frequency: Always Happens
Regression: I don't know if this issue existed previously

Problem Description:
Using paramter validation in functions works just find - something like this:
function test{
Param (
[ValidateRange(3,8)]
[Int] $mytest )

write-host $mytest
}
test 4
test 9
The problem is, that it seems, that parameter validation is in fact just a special case of variable validation which leads to the circumstance, that the variable used (in this case $mytest) is beeing validated every time you use it. Try this:
function test{
Param (
[ValidateRange(3,8)]
[Int] $mytest)

$mytest = $mytest+5
write-host $mytest
}

test 4

It seems to be by design, but the documentation about parameter validation is misleading if not completly wrong, because it says something like:"parameters are validated when you call the function/cmdlet", which simply is not the way it works - the variable is validated everytime you use it.

Product Studio item created by Connect Synchronizer due to creation of feedback ID 1117495 (http://connect.microsoft.com/PowerShell/feedback/ViewFeedback.aspx?FeedbackID=1117495).

Repro Steps:
function test{
Param (
[ValidateRange(3,8)]
[Int] $mytest)

$mytest = $mytest+5
write-host $mytest
}

test 4

Expected Results:
test 4
The variable cannot be validated because the value 9 is not a valid value for the mytest variable.
At line:6 char:5
+ $mytest = $mytest+5
+ ~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : MetadataError: (:) [], ValidationMetadataException
+ FullyQualifiedErrorId : ValidateSetFailure

4

Internal BugId: 13225

1 vote
Sign in
(thinking…)
Sign in with: Facebook Google
Signed in as (Sign out)

We’ll send you updates on this idea

AdminJoey Aiello [MSFT] (Program Manager, Windows Server) shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

0 comments

Sign in
(thinking…)
Sign in with: Facebook Google
Signed in as (Sign out)
Submitting...

Feedback and Knowledge Base