|
BUG? (Test-Path $path -IsValid) and empty $path I would like to check if $path is a syntactically valid path using Test-Path
with -IsValid switch , i.e.:
PS> $path = '' # why not?
PS> if (!(Test-Path $path -IsValid)) {Write-Warning "Path <$path> is
invalid"}
Surprisingly Test-Path fails and instead of expected
WARNING: Path <> is invalid
I get very disappointing:
Test-Path : Cannot bind argument to parameter 'Path' because it is an
empty string.
The problem is not just a misleading message, but something worse - my code
was not executed as it was designed for an invalid path.
Note: I can’t even suppress this failure:
PS> Test-Path '' -ea SilentlyContinue
Test-Path : Cannot bind argument to parameter 'Path' because it is an
empty string.
Then, if -Path is an empty string, there are even more oddities:
PS> Test-Path '' -xxx
Instead of more likely expected error
Test-Path : A parameter cannot be found that matches parameter name 'xxx'.
I get again
Test-Path : Cannot bind argument to parameter 'Path' because it is an
empty string.
All this does not look good, IMO.
Any ideas? Am I missing something?
--
Thanks,
Roman |