Skip to content

Testing whitespace returns true (but docs say 'false') #5078

@DotNetSparky

Description

@DotNetSparky

Example 8 (Test a path with whitespace as the value) says:

When a whitespace is or empty string in provided for the the -Path parameter, it returns false. The following example show whitespace and empty string.

I just tried this on my machine, and it seems to return true if you test a path that is just white-space:

Test-Path ' '
True
Test-Path ' ' -IsValid
True
Test-Path ''
Test-Path : Cannot bind argument to parameter 'Path' because it is an empty string.
At line:1 char:11
+ Test-Path ''
+           ~~
    + CategoryInfo          : InvalidData: (:) [Test-Path], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.PowerShell.Commands.TestPathCommand

Test-Path '' -IsValid
Test-Path : Cannot bind argument to parameter 'Path' because it is an empty string.
At line:1 char:11
+ Test-Path '' -IsValid
+           ~~
    + CategoryInfo          : InvalidData: (:) [Test-Path], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.PowerShell.Commands.TestPathCommand

$PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.19018.1
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19018.1
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Metadata

Metadata

Assignees

Labels

area-managementArea - Microsoft.PowerShell.Management module

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions