Quantcast
Channel: PowerShell.org » All Posts
Viewing all articles
Browse latest Browse all 13067

Reply To: Correct usage of [Validatenotnullorempty]

$
0
0

The behaviour is expected.

Try this

£> test

cmdlet test at command pipeline position 1
Supply values for the following parameters:
Path:
test : Cannot validate argument on parameter ‘Path’. The argument is null or empty. Provide an argument that is not
null or empty, and then try the command again.
At line:1 char:1
+ test
+ ~~~~
+ CategoryInfo : InvalidData: (:) [test], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,test

You’ve called the function with an empty path & generated the error

If you look at your dir command
£> dir c:\ -Filter Idontexist

Nothing is returned – which means that nothing is on the pipeline so your test function isn’t called because no objects enter that part of the pipeline

If you call the function like this

£> test -Path (dir c:\ -Filter Idontexist)
test : Cannot validate argument on parameter ‘Path’. The argument is null or empty. Provide an argument that is not
null or empty, and then try the command again.
At line:1 char:12
+ test -Path (dir c:\ -Filter Idontexist)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [test], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,test

you’ll see the error because you’re passing in an empty path.


Viewing all articles
Browse latest Browse all 13067

Trending Articles