Combine a path and one or more child-paths into a single path.
Syntax
Join-Path [-path] string[] [-childPath] string [-resolve]
[-credential PSCredential] [-UseTransaction] [CommonParameters]
Key
-Path string[]
The main path (or paths) to which the child-path is appended.
Wildcards are permitted. May be piped.
-childPath string
The elements to append to the value of Path.
Wildcards are permitted. May be piped.
-resolve
Display the items that are referenced by the joined path.
If the items do not exist in the current session an error will be raised.
Where a wildcard is used, display all the matching items.
-credential PSCredential
Use a credential to validate access to the file. Credential represents
a user-name, such as "User01" or "Domain01\User01", or a PSCredential
object, such as the one retrieved by using the Get-Credential cmdlet.
If you type a user name, you will be prompted for a password.
This parameter is not supported by any PowerShell core cmdlets or providers.
-UseTransaction
Include the command in the active transaction.
The appropriate path delimiters will be supplied by the provider.
In PowerShell 6.0 and above, join-path can combine an indefinite number of child paths.
.NET equivalent to Join-Path:
PS C:\> [System.IO.Path]::Combine('path', 'childPath')
Join two paths:
PS C:\> Join-Path -path c:\win* -childpath system*
C:\win*\System*
Join two paths with a wildcard and display the matching files and folders, -resolve will display the full pathnames:
PS C:\> Join-Path -path c:\win* system* -resolve
C:\Windows\System
C:\Windows\System32
...
C:\Windows\System.ini
Join two paths with a single character wildcard (?) and display the matching files and folders, -resolve will display the full pathnames, if they exist:
PS C:\> Join-Path -path "c:\batch" -childpath Project? -resolve
C:\batch\Project1
C:\batch\Project2
Join two paths that don't exist and attempt to resolve them, this will raise an error:
PS C:\> Join-Path -path "c:\Windows" -childpath "AfolderThatDoesntExist" -resolve
Display the registry keys in the HKLM\System hive that include "ControlSet":
PS C:\> Set-Location HKLM:
PS HKLM:\> join-path System *ControlSet* -resolve
HKLM:\System\ControlSet001
HKLM:\System\ControlSet002
HKLM:\System\CurrentControlSet
Combine multiple path roots with a child path:
PS C:\> Join-Path -Path C:, D:, E:, F: -ChildPath New
C:\New
D:\New
E:\New
F:\New
#Here come old flattop, he come grooving up slowly, He got joo-joo eyeball, he one holy roller# ~ The Beatles (Come Together)
Convert-Path - Convert a ps path to a provider path.
Resolve-Path - Resolve the wildcards in a path.
Split-Path - Return part of a path.
Test-Path - Return true if the path exists, otherwise return false.
Get-Help about_namespace