PowerShell Logo Small

Test-Path



This is the built-in help made by Microsoft for the command 'Test-Path', in PowerShell version 3 - as retrieved from Windows version 'Microsoft Windows Server 2012 Standard' 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 file or directory path exist.

SYNTAX


Test-Path [-Path] <String[]> [-Credential <PSCredential>] [-Exclude <String[]>] [-Filter <String>] [-Include <String[]>] [-IsValid] [-PathType
<TestPathType>] [-UseTransaction [<SwitchParameter>]] [<CommonParameters>]
Test-Path [-Credential <PSCredential>] [-Exclude <String[]>] [-Filter <String>] [-Include <String[]>] [-IsValid] [-PathType <TestPathType>]
-LiteralPath <String[]> [-UseTransaction [<SwitchParameter>]] [<CommonParameters>]
Test-Path [-NewerThan <DateTime>] [-OlderThan <DateTime>] [<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 are missing. It can also tell whether the path syntax is valid and whether the path leads to a container or a terminal (leaf) element.

In a file system drive, Test-Path can tell whether a path is valid, whether all elements of the path exist, or report whether a path leads to
a file or a directory. It can also tell whether a file was changed before or after a particular date.

Note: This custom cmdlet help file explains how the Test-Path cmdlet works in a file system drive. For information about the Test-Path cmdlet
in all drives, type "Get-Help Test-Path -Path $null" or see Test-Path at http://go.microsoft.com/fwlink/?LinkID=113418.



<

RELATED LINKS

Online version: http://go.microsoft.com/fwlink/?LinkId=231703
Test-Path
(generic); http://go.microsoft.com/fwlink/?LinkID=113418
FileSystem Provider
Clear-Content
Get-Content
Get-ChildItem
Get-Content
Get-Item
Remove-Item
Set-Content
Test-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
directory. 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 for 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, and 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
.ps1 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
installed 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, but if you use it to test the path to a registry entry, it always returns FALSE, even if the registry entry is present.








-------------------------- EXAMPLE 6 --------------------------

C:\PS>Test-Path $pshome\PowerShell.exe -NewerThan "July 13, 2009"



Description

-----------

This command uses the NewerThan dynamic parameter to determine whether the PowerShell.exe file on the computer is newer than July 13, 2009.

The NewerThan parameter works only in file system drives.