Join-Path

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.

   -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')

Examples

Join two paths:

PS C:\> Join-Path -path c:\win* -childpath system*

The above will resolve to: C:\windows\System

Join 2 paths and display the files and folders, -resolve will display the full pathname:

PS C:\> Join-Path -path c:\win* system* -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

#Here come old flattop, he come grooving up slowly, He got joo-joo eyeball, he one holy roller# ~ The Beatles (Come Together)

Related PowerShell Cmdlets

convert-path - Convert a ps path to a provider path.
resolve-path - Resolves 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


 
Copyright © 1999-2024 SS64.com
Some rights reserved