PowerShell Logo Small

Test-Path



This is the built-in help made by Microsoft for the command 'Test-Path', in PowerShell version 2 - as retrieved from Windows version 'Microsoft® Windows Vista™ Ultimate ' PowerShell help files on 2016-06-23.

For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.

SYNOPSIS

Determines whether all elements of a path exist.

SYNTAX


Test-Path [-LiteralPath] <string[]> [-Credential <PSCredential>] [-Exclude <string[]>] [-Filter <string>] [-Include <string[]>] [-IsValid] [-Path
Type {Any | Container | Leaf}] [-UseTransaction] [<CommonParameters>]
Test-Path [-Path] <string[]> [-Credential <PSCredential>] [-Exclude <string[]>] [-Filter <string>] [-Include <string[]>] [-IsValid] [-PathType {A
ny | Container | Leaf}] [-UseTransaction] [<CommonParameters>]



Search powershellhelp.space

DESCRIPTION


The Test-Path cmdlet determines whether all elements of the path exist. It returns TRUE ($true) if all elements exist and FALSE ($false) if any a
re missing. It can also tell whether the path syntax is valid and whether the path leads to a container or a terminal (leaf) element.



<

RELATED LINKS

Online version: http://go.microsoft.com/fwlink/?LinkID=113418
about_Providers
Convert-Path
Split-Path
Resolve-Path
Join-Path

REMARKS

<

Examples


-------------------------- EXAMPLE 1 --------------------------

C:\PS>test-path -path "C:\Documents and Settings\NicoleH"



Description
-----------
This command tells whether all elements in the path exist, that is, the C: directory, the Documents and Settings directory, and the NicoleH direc
tory. If any are missing, the cmdlet returns FALSE. Otherwise, it returns TRUE.








-------------------------- EXAMPLE 2 --------------------------

C:\PS>test-path -path $profile

C:\PS>test-path -path $profile -IsValid



Description
-----------
These commands test the path to the Windows PowerShell profile.

The first command determines whether all elements in the path exist. The second command determines whether the syntax of the path is correct. In
this case, the path is FALSE, but the syntax is correct (TRUE). These commands use $profile, the automatic variable that points to the location f
or the profile, even if the profile does not exist.

For more information about automatic variables, see about_Automatic_Variables.








-------------------------- EXAMPLE 3 --------------------------

C:\PS>test-path -path "C:\CAD\Commercial Buildings\*" -exclude *.dwg



Description
-----------
This command tells whether there are any files in the Commercial Buildings directory other than .dwg files.

The command uses the Path parameter to specify the path. Because it includes a space, the path is enclosed in quotes. The asterisk at the end of
the path indicates the contents of the Commercial Building directory. (With long paths, like this one, type the first few letters of the path, an
d then use the TAB key to complete the path.)

The command uses the Exclude parameter to specify files that will be omitted from the evaluation.

In this case, because the directory contains only .dwg files, the result is FALSE.








-------------------------- EXAMPLE 4 --------------------------

C:\PS>test-path -path $profile -pathtype leaf



Description
-----------
This command tells whether the path stored in the $profile variable leads to a file. In this case, because the Windows PowerShell profile is a .p
s1 file, the cmdlet returns TRUE.








-------------------------- EXAMPLE 5 --------------------------

C:\PS>test-path -path HKLM:\Software\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell

TRUE

C:\PS> test-path -path HKLM:\Software\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell\ExecutionPolicy
FALSE



Description
-----------
These commands use the Test-Path cmdlet with the Windows PowerShell registry provider.

The first command tests whether the registry path to the Microsoft.PowerShell registry key is correct on the system. If Windows PowerShell is ins
talled correctly, the cmdlet returns TRUE.

Test-Path does not work correctly with all Windows PowerShell providers. For example, you can use Test-Path to test the path to a registry key, b
ut if you use it to test the path to a registry entry, it always returns FALSE, even if the registry entry is present.