-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Closed
Labels
Issue-Enhancementthe issue is more of a feature request than a bugthe issue is more of a feature request than a bugResolution-FixedThe issue is fixed.The issue is fixed.WG-Cmdlets-Managementcmdlets in the Microsoft.PowerShell.Management modulecmdlets in the Microsoft.PowerShell.Management module
Description
Test-Path will throw an error when the path is $null (or an empty string) instead of returning $false.
The errors that we do get are parameter binding errors
I find myself often running into errors with Test-Path because of empty or $null strings. Then I end up making my validation more complex to account for it.
if ( Test-Path -Path $Path)
{
# do something
}
# VS
if ( $null -ne $Path -and ( Test-Path -Path $Path) )
{
# do something
}
It would be nice if it would just return $false (or offer a -Quiet parameter)
Steps to reproduce
$path = Resolve-Path -Path '.\*\nothing'
Test-Path $pathResolve-Path -Path '.\*\nothing' | Test-PathExpected behavior
False
Actual behavior
Error: Test-Path : Cannot bind argument to parameter 'Path' because it is null.
Environment data
> $PSVersionTable
PSVersion 6.1.0
PSEdition Core
GitCommitId 6.1.0
OS Microsoft Windows 10.0.16299
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0vexx32, SeeminglyScience, mkht, mklement0, The-New-Guy and 3 more
Metadata
Metadata
Assignees
Labels
Issue-Enhancementthe issue is more of a feature request than a bugthe issue is more of a feature request than a bugResolution-FixedThe issue is fixed.The issue is fixed.WG-Cmdlets-Managementcmdlets in the Microsoft.PowerShell.Management modulecmdlets in the Microsoft.PowerShell.Management module