Test-PathIsJunction

Tests if a path is a junction.

Syntax

Test-PathIsJunction [-Path] <String> [<CommonParameters>]

Test-PathIsJunction -LiteralPath <String> [<CommonParameters>]

Description

The Test-PathIsJunction function tests if path is a junction (i.e. reparse point). If the path doesn't exist, returns $false.

Carbon adds an IsJunction extension method on DirectoryInfo objects, which you can use instead e.g.

Get-ChildItem -Path $env:Temp | 
    Where-Object { $_.PsIsContainer -and $_.IsJunction }

would return all the junctions under the current user's temporary directory.

The LiteralPath parameter was added in Carbon 2.2.0. Use it to check paths that contain wildcard characters.

Parameters

Name Type Description Required? Pipeline Input Default Value
Path String

The path to check. Wildcards allowed. If using wildcards, returns $true if all paths that match the wildcard are junctions. Otherwise, return $false.

true false
LiteralPath String

The literal path to check. Use this parameter to test a path that contains wildcard characters.

This parameter was added in Carbon 2.2.0.

true false

EXAMPLE 1

Test-PathIsJunction -Path C:\I\Am\A\Junction

Returns $true.

EXAMPLE 2

Test-PathIsJunction -Path C:\I\Am\Not\A\Junction

Returns $false.

EXAMPLE 3

Get-ChildItem * | Where-Object { $_.PsIsContainer -and $_.IsJunction }

Demonstrates an alternative way of testing for junctions. Uses Carbon's IsJunction extension method on the DirectoryInfo type to check if any directories under the current directory are junctions.

EXAMPLE 4

Test-PathIsJunction -LiteralPath 'C:\PathWithWildcards[]'

Demonstrates how to test if a path with wildcards is a junction.