Skip to content

Add description and example about null paths for Test-Path #4036

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 22, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add description and example about null paths
  • Loading branch information
adityapatwardhan committed Mar 22, 2019
commit c63e027359f7d076c0be74d6a3f47c2604ebdb16
40 changes: 37 additions & 3 deletions reference/6/Microsoft.PowerShell.Management/Test-Path.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
ms.date: 10/18/2018
ms.date: 03/22/2019
schema: 2.0.0
locale: en-us
keywords: powershell,cmdlet
Expand All @@ -10,6 +10,7 @@ title: Test-Path
# Test-Path

## SYNOPSIS

Determines whether all elements of a path exist.

## SYNTAX
Expand All @@ -35,6 +36,8 @@ Test-Path -LiteralPath <String[]> [-Filter <String>] [-Include <String[]>] [-Exc
The `Test-Path` cmdlet determines whether all elements of the path exist.
It returns `$True` if all elements exist and `$False` if any are missing.
It can also tell whether the path syntax is valid and whether the path leads to a container or a terminal or leaf element.
If the `Path` is whitespace, then `$False` is returned.
If the `Path` is `$null`, array of `$null` or empty array, a non-terminating error is returned.

## EXAMPLES

Expand Down Expand Up @@ -111,7 +114,7 @@ True
```

This command checks whether the path stored in the `$profile` variable leads to a file.
In this case, because the PowerShell profile is a .ps1 file, the cmdlet returns `$True`.
In this case, because the PowerShell profile is a `.ps1` file, the cmdlet returns `$True`.

### Example 5: Check paths in the Registry

Expand Down Expand Up @@ -154,11 +157,42 @@ Test-Path $pshome\PowerShell.exe -NewerThan "July 13, 2009"
True
```

### Example 7: Test a path with null as the value

```powershell
Test-Path $null
Test-Path $null, $null
Test-Path @()
```

```output
Test-Path : Value cannot be null.
Parameter name: The provided Path argument was null or an empty collection.
At line:1 char:1
+ Test-Path @()
+ ~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (System.String[]:String[]) [Test-Path], ArgumentNullException
+ FullyQualifiedErrorId : NullPathNotPermitted,Microsoft.PowerShell.Commands.TestPathCommand
```

The error returned for `null`, array of `null` or empty array is a non-terminating error and can be suppress by using `-ErrorAction SilentlyContinue`.

### Example 8: Test a path with whitespace as the value

```powershell
Test-Path ' '
Test-Path ''
```

```output
False
```

## PARAMETERS

### -Credential

Specifies a user account that has permission to perform this action.
Specifies a user account that has permission to do this action.
The default is the current user.

Type a user name, such as User01 or Domain01\User01.
Expand Down