Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Test-Path '' -IsValid does not return False but fails. Is this OK?

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 11-08-2007   #1 (permalink)
Roman Kuzmin
Guest


 

Test-Path '' -IsValid does not return False but fails. Is this OK?

Test-Path $Path -IsValid fails with ParameterBindingValidationException
(Test-Path : Cannot bind argument to parameter 'Path' because it is...) is
$Path is null or an empty string.

As a result one has to check validity of $Path in this way:
if ($Path -and (Test-Path $Path -IsValid)) {...}

Is this intentional?

--
Thanks,
Roman Kuzmin
PowerShellFar and FarNET: http://code.google.com/p/farnet/




My System SpecsSystem Spec
Old 11-08-2007   #2 (permalink)
Shay Levi
Guest


 

Re: Test-Path '' -IsValid does not return False but fails. Is this OK?

There is no default value for -path (as opposed to get-childitem which lists
the current directory), so it fails.
You need to validate $path prior to testing it. -isValid can only run if
the $path is not null or empty.

You can see it by running:

PS > test-path
cmdlet test-path at command pipeline position 1
Supply values for the following parameters:
Path[0]:
Test-Path : Cannot bind argument to parameter 'Path' because it is an empty
array.
At line:1 char:9
+ test-path <<<<

Is it intensional? I think it is. Here's what the help says (it's required):

PARAMETERS
-path <string[]>
Specifies a path to be tested. Wildcards are permitted. If the path
includes spaces, enclose it in quotation marks. The parameter n
ame ("-Path") is optional.

Required? true
...



-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com


Quote:

> Test-Path $Path -IsValid fails with
> ParameterBindingValidationException (Test-Path : Cannot bind argument
> to parameter 'Path' because it is...) is $Path is null or an empty
> string.
>
> As a result one has to check validity of $Path in this way: if ($Path
> -and (Test-Path $Path -IsValid)) {...}
>
> Is this intentional?
>

My System SpecsSystem Spec
Old 11-08-2007   #3 (permalink)
Roman Kuzmin
Guest


 

Re: Test-Path '' -IsValid does not return False but fails. Is this OK?

> Is it intensional? I think it is. Here's what the help says (it's
Quote:

> required):
Perhaps you are talking about something else. Empty string or null
parameters are not the same as omitted parameters.

$Path = ''
Test-Path -Path $Path -IsValid

Output:
Test-Path : Cannot bind argument to parameter 'Path' because it is an empty
string.
....

Note, I do provide parameter -Path, so that 'required' is satisfied. But I
rather expect

Output:
False

than a failure message in this case.

--
Thanks,
Roman Kuzmin
PowerShellFar and FarNET: http://code.google.com/p/farnet/


My System SpecsSystem Spec
Old 11-08-2007   #4 (permalink)
Shay Levi
Guest


 

Re: Test-Path '' -IsValid does not return False but fails. Is this OK?

I can see what you mean.

-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com


Quote:
Quote:

>> Is it intensional? I think it is. Here's what the help says (it's
>> required):
>>
> Perhaps you are talking about something else. Empty string or null
> parameters are not the same as omitted parameters.
>
> $Path = ''
> Test-Path -Path $Path -IsValid
> Output:
> Test-Path : Cannot bind argument to parameter 'Path' because it is an
> empty
> string.
> ...
> Note, I do provide parameter -Path, so that 'required' is satisfied.
> But I rather expect
>
> Output:
> False
> than a failure message in this case.
>

My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
test-path -IsValid ? Ray PowerShell 2 04-03-2008 06:48 AM
Test-Path isValid parameter Shay Levi PowerShell 5 09-20-2007 09:53 AM
Get-Location return for UNC path ~Clint PowerShell 2 12-05-2006 05:34 PM
how to test for a program in my path? =?Utf-8?B?R2lsIE5vdmFr?= PowerShell 2 09-26-2006 05:12 PM
BUG? (Test-Path $path -IsValid) and empty $path =?Utf-8?B?Um9tYW4gS3V6bWlu?= PowerShell 1 08-28-2006 12:10 PM


Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51