Reputation: 9387
based on documentation -IsValid is supposed to check if the syntax of the path is correct. Anything i put for the Test-Path it always return true
Indicates that this cmdlet tests the syntax of the path, regardless of whether the elements of the path exist. This cmdlet returns $True if the path syntax is valid and $False if it is not
$val = Test-Path "sadfasdasdfasdf" -IsValid
Upvotes: 2
Views: 1365
Reputation: 24071
It may certainly look like everything goes, but that's not the case. The -IsValid
only does syntax check. There's nothing wrong with the syntax: "sadfasdasdfasdf"
could very well be a subdirectory within current directory.
For example, the following paths are using incorrect syntax and thus not valid:
PS C:\> Test-Path "foo>bar" -IsValid # Redirection in path
False
PS C:\> Test-Path "foo:bar" -IsValid # Edge case, HKLM:USER would be valid
False
PS C:\> Test-Path "foo|bar" -IsValid # Pipe in path
False
Upvotes: 6