22external help file : Microsoft.PowerShell.Commands.Management.dll-Help.xml
33Locale : en-US
44Module Name : Microsoft.PowerShell.Management
5- ms.date : 02/16/2023
5+ ms.date : 01/19/2024
66online version : https://learn.microsoft.com/powershell/module/microsoft.powershell.management/test-path?view=powershell-5.1&WT.mc_id=ps-gethelp
77schema : 2.0.0
88title : Test-Path
@@ -48,11 +48,11 @@ Test-Path -LiteralPath <string[]> [-Filter <string>] [-Include <string[]>] [-Exc
4848
4949## DESCRIPTION
5050
51- The ` Test-Path ` cmdlet determines whether all elements of the path exist. It returns ` $True ` if all
52- elements exist and ` $False ` if any are missing. It can also tell whether the path syntax is valid
51+ The ` Test-Path ` cmdlet determines whether all elements of the path exist. It returns ` $true ` if all
52+ elements exist and ` $false ` if any are missing. It can also tell whether the path syntax is valid
5353and whether the path leads to a container or a terminal or leaf element. If the ** Path** is a
54- whitespace or empty string, then ` $False ` is returned . If the ** Path** is ` $null ` , array of ` $null `
55- or empty array, a non-terminating error is returned .
54+ whitespace or empty string, then the cmdlet returns ` $false ` . If the ** Path** is ` $null ` , an array
55+ of ` $null ` or an empty array, the cmdlet returns a non-terminating error.
5656
5757## EXAMPLES
5858
@@ -66,9 +66,9 @@ Test-Path -Path "C:\Documents and Settings\DavidC"
6666True
6767```
6868
69- This command checks whether all elements in the path exist, that is, the ` C: ` directory, the
69+ This command checks whether all elements in the path exist, including the ` C: ` directory, the
7070` Documents and Settings ` directory, and the ` DavidC ` directory. If any are missing, the cmdlet
71- returns ` $False ` . Otherwise, it returns ` $True ` .
71+ returns ` $false ` . Otherwise, it returns ` $true ` .
7272
7373### Example 2: Test the path of a profile
7474
9191These commands test the path of the PowerShell profile.
9292
9393The first command determines whether all elements in the path exist. The second command determines
94- whether the syntax of the path is correct. In this case, the path is ` $False ` , but the syntax is
95- correct ` $True ` . These commands use ` $profile ` , the automatic variable that points to the location
96- for the profile, even if the profile does not exist.
94+ whether the syntax of the path is correct. In this case, the path is ` $false ` , but the syntax is
95+ correct ` $true ` . These commands use ` $profile ` , the automatic variable that points to the location
96+ for the profile, even if the profile doesn't exist.
9797
98- For more information about automatic variables, see [ about_Automatic_Variables] ( ../Microsoft.PowerShell.Core/About/about_Automatic_Variables.md ) .
98+ For more information about automatic variables, see
99+ [ about_Automatic_Variables] ( ../Microsoft.PowerShell.Core/About/about_Automatic_Variables.md ) .
99100
100101### Example 3: Check whether there are any files besides a specified type
101102
@@ -115,10 +116,9 @@ path is enclosed in quotation marks. The asterisk at the end of the path indicat
115116the Commercial Building directory. With long paths, such as this one, type the first few letters of
116117the path, and then use the TAB key to complete the path.
117118
118- The command specifies the ** Exclude** parameter to specify files that will be omitted from the
119- evaluation.
119+ The command specifies the ** Exclude** parameter to specify files to omit from the evaluation.
120120
121- In this case, because the directory contains only .dwg files, the result is ` $False ` .
121+ In this case, because the directory contains only .dwg files, the result is ` $false ` .
122122
123123### Example 4: Check for a file
124124
@@ -131,19 +131,19 @@ True
131131```
132132
133133This command checks whether the path stored in the ` $profile ` variable leads to a file. In this
134- case, because the PowerShell profile is a ` .ps1 ` file, the cmdlet returns ` $True ` .
134+ case, because the PowerShell profile is a ` .ps1 ` file, the cmdlet returns ` $true ` .
135135
136136### Example 5: Check paths in the Registry
137137
138138These commands use ` Test-Path ` with the PowerShell registry provider.
139139
140140The first command tests whether the registry path of the ** Microsoft.PowerShell** registry key is
141- correct on the system. If PowerShell is installed correctly, the cmdlet returns ` $True ` .
141+ correct on the system. If PowerShell is installed correctly, the cmdlet returns ` $true ` .
142142
143143> [ !IMPORTANT]
144- > ` Test-Path ` does not work correctly with all PowerShell providers. For example, you can use
144+ > ` Test-Path ` doesn't work correctly with all PowerShell providers. For example, you can use
145145> ` Test-Path ` to test the path of a registry key, but if you use it to test the path of a registry
146- > entry, it always returns ` $False ` , even if the registry entry is present.
146+ > entry, it always returns ` $false ` , even if the registry entry is present.
147147
148148``` powershell
149149Test-Path -Path "HKLM:\Software\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell"
@@ -163,8 +163,8 @@ False
163163
164164### Example 6: Test if a file is newer than a specified date
165165
166- This command uses the ** NewerThan** dynamic parameter to determine whether the " PowerShell.exe" file
167- on the computer is newer than " July 13, 2009" .
166+ This command uses the ** NewerThan** dynamic parameter to determine whether the ` PowerShell.exe `
167+ file on the computer is newer than ` July 13, 2009 ` .
168168
169169The NewerThan parameter works only in file system drives.
170170
179179### Example 7: Test a path with null as the value
180180
181181The error returned for ` null ` , array of ` null ` or empty array is a non-terminating error. It can be
182- suppress by using ` -ErrorAction SilentlyContinue ` . The following example shows all cases which
182+ suppress by using ` -ErrorAction SilentlyContinue ` . The following example shows all cases that
183183return the ` NullPathNotPermitted ` error.
184184
185185``` powershell
@@ -199,9 +199,9 @@ At line:1 char:11
199199
200200### Example 8: Test a path with whitespace as the value
201201
202- When a whitespace string is provided for the the ** Path** parameter, it returns ** True ** . When an
203- empty string is provided, ` Test-Path ` returns an error. The following example shows whitespace and
204- empty string.
202+ When a whitespace string is provided for the ** Path** parameter, it returns ` $true ` . When an empty
203+ string is provided, ` Test-Path ` returns an error. The following example shows whitespace and empty
204+ string.
205205
206206``` powershell
207207Test-Path ' '
@@ -242,7 +242,7 @@ Accept wildcard characters: False
242242### -Exclude
243243
244244Specifies items that this cmdlet omits. The value of this parameter qualifies the **Path**
245- parameter. Enter a path element or pattern, such as " *.txt" . Wildcard characters are permitted.
245+ parameter. Enter a path element or pattern, such as ` *.txt` . Wildcard characters are permitted.
246246
247247` ` ` yaml
248248Type: System.String[]
@@ -260,8 +260,8 @@ Accept wildcard characters: True
260260
261261Specifies a filter in the format or language of the provider. The value of this parameter qualifies
262262the **Path** parameter. The syntax of the filter, including the use of wildcard characters, depends
263- on the provider. Filters are more efficient than other parameters, because the provider applies them
264- when it retrieves the objects instead of having PowerShell filter the objects after they are
263+ on the provider. Filters are more efficient than other parameters, because the provider applies
264+ them when it retrieves the objects instead of having PowerShell filter the objects after they're
265265retrieved.
266266
267267` ` ` yaml
@@ -279,7 +279,7 @@ Accept wildcard characters: True
279279# ## -Include
280280
281281Specifies paths that this cmdlet tests. The value of this parameter qualifies the **Path**
282- parameter. Enter a path element or pattern, such as " *.txt" . Wildcard characters are permitted.
282+ parameter. Enter a path element or pattern, such as ` *.txt` . Wildcard characters are permitted.
283283
284284` ` ` yaml
285285Type: System.String[]
@@ -296,7 +296,7 @@ Accept wildcard characters: True
296296# ## -IsValid
297297
298298Indicates that this cmdlet tests the syntax of the path, regardless of whether the elements of the
299- path exist. This cmdlet returns ` $True ` if the path syntax is valid and `$False ` if it is not.
299+ path exist. This cmdlet returns `$true ` if the path syntax is valid and `$false ` if it's not.
300300
301301` ` ` yaml
302302Type: System.Management.Automation.SwitchParameter
@@ -313,9 +313,9 @@ Accept wildcard characters: False
313313# ## -LiteralPath
314314
315315Specifies a path to be tested. Unlike **Path**, the value of the **LiteralPath** parameter is used
316- exactly as it is typed. No characters are interpreted as wildcard characters. If the path includes
317- characters that could be interpreted by PowerShell as escape sequences, you must enclose the path in
318- single quote so that they won't be interpreted.
316+ exactly as it's typed. No characters are interpreted as wildcard characters. If the path includes
317+ characters that could be interpreted by PowerShell as escape sequences, you must enclose the path
318+ in single quote so that they won't be interpreted.
319319
320320` ` ` yaml
321321Type: System.String[]
@@ -335,6 +335,16 @@ This is a dynamic parameter made available by the **FileSystem** provider.
335335
336336Specify a time as a **DateTime** object.
337337
338+ Before PowerShell 7.5, the cmdlet ignores :
339+
340+ - This parameter when you specify **PathType** as any value other than `Any`.
341+ - The **OlderThan** parameter when used with this parameter.
342+ - This parameter when **Path** points to a directory.
343+
344+ Starting with PowerShell 7.5, you can use this parameter with any value for the **PathType**
345+ parameter, to test a date range with the **OlderThan** parameter, and to test the age of
346+ directories.
347+
338348For more information, see
339349[about_FileSystem_Provider](../Microsoft.PowerShell.Core/About/about_FileSystem_Provider.md).
340350
@@ -356,6 +366,16 @@ This is a dynamic parameter made available by the **FileSystem** provider.
356366
357367Specify a time as a **DateTime** object.
358368
369+ Before PowerShell 7.5, the cmdlet ignores:
370+
371+ - This parameter when you specify **PathType** as any value other than ` Any`.
372+ - This parameter when used with the **NewerThan** parameter.
373+ - This parameter when **Path** points to a directory.
374+
375+ Starting with PowerShell 7.5, you can use this parameter with any value for the **PathType**
376+ parameter, to test a date range with the **NewerThan** parameter, and to test the age of
377+ directories.
378+
359379For more information, see
360380[about_FileSystem_Provider](../Microsoft.PowerShell.Core/About/about_FileSystem_Provider.md).
361381
@@ -390,24 +410,24 @@ Accept wildcard characters: True
390410
391411### -PathType
392412
393- Specifies the type of the final element in the path. This cmdlet returns ` $True ` if the element is
394- of the specified type and `$False ` if it is not. The acceptable values for this parameter are :
413+ Specifies the type of the final element in the path. This cmdlet returns ` $true ` if the element is
414+ of the specified type and `$false ` if it's not. The acceptable values for this parameter are :
395415
396416- ` Container` - An element that contains other elements, such as a directory or registry key.
397- - ` Leaf` - An element that does not contain other elements, such as a file.
417+ - ` Leaf` - An element that doesn't contain other elements, such as a file.
398418- ` Any` - Either a container or a leaf.
399419
400420Tells whether the final element in the path is of a particular type.
401421
402422> [!CAUTION]
403423>
404- > Up to PowerShell version 6.1.2, when the **IsValid** and **PathType** switches are
405- > specified together, the `Test-Path` cmdlet ignores the **PathType** switch and only
406- > validates the syntactic path without validating the path type.
424+ > Up to PowerShell version 6.1.2, when the **IsValid** and **PathType** switches are specified
425+ > together, the `Test-Path` cmdlet ignores the **PathType** switch and only validates the syntactic
426+ > path without validating the path type.
407427>
408428> According to [issue # 8607](https://github.com/PowerShell/PowerShell/issues/8607), fixing this
409429> behavior may be a breaking change in a future version, where the **IsValid** and **PathType**
410- > switches belong to separate parameter sets, and thus, cannot be used together avoiding this
430+ > switches belong to separate parameter sets, and thus, can't be used together avoiding this
411431> confusion.
412432
413433` ` ` yaml
@@ -461,14 +481,15 @@ The cmdlet returns a **Boolean** value.
461481
462482# # NOTES
463483
464- The cmdlets that contain the **Path** noun (the **Path** cmdlets) work with path names and return
465- the names in a concise format that all PowerShell providers can interpret. They are designed for use
466- in programs and scripts where you want to display all or part of a path name in a particular format.
467- Use them as you would use **Dirname**, **Normpath**, **Realpath**, **Join**, or other path
484+ The cmdlets that contain the **Path** noun (the **Path** cmdlets) work with path and return the
485+ names in a concise format that all PowerShell providers can interpret. They're designed for use in
486+ programs and scripts where you want to display all or part of a path in a particular format. Use
487+ them as you would use **Dirname**, **Normpath**, **Realpath**, **Join**, or other path
468488manipulators.
469489
470490The `Test-Path` is designed to work with the data exposed by any provider. To list the providers
471- available in your session, type `Get-PSProvider`. For more information, see [about_Providers](../Microsoft.PowerShell.Core/About/about_Providers.md).
491+ available in your session, type `Get-PSProvider`. For more information, see
492+ [about_Providers](../Microsoft.PowerShell.Core/About/about_Providers.md).
472493
473494# # RELATED LINKS
474495
0 commit comments