EDUCBA

EDUCBA

MENUMENU
  • Explore
    • Lifetime Membership
    • All in One Bundles
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign up
Home Data Science Data Science Tutorials PowerShell Tutorial PowerShell Join-Path

PowerShell Join-Path

Updated March 6, 2023

PowerShell Join-Path

Introduction to PowerShell Join-Path

The following article provides an outline for PowerShell Join-Path. There may be scenarios where a user might want to combine two paths into a single path; in that case, the user should use the join-path cmdlet. There will be one parent path, and multiple child paths can be appended to the parent path to create a new path. This can be used with several of the providers such as registry, filesystem and certificates, to name a few. The path parameter manipulates and returns the path in a format that is easily recognizable by PowerShell. Here we will see in detail about the various parameters and ways of joining multiple paths.

ADVERTISEMENT
Popular Course in this category
WINDOWS POWERSHELL Course Bundle - 7 Courses in 1

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

Syntax of PowerShell Join-Path

The syntax of the Join-Path cmdlet is as follows:

Name:

Join-Path

Syntax:

Join-Path [-Path] <string[]> [-ChildPath] <string> [-Resolve] [-Credential <pscredential>] [-UseTransaction] [<CommonParameters>]

Aliases:

None

Example:

Code:

Write-Host "Demo of join path" -ForegroundColor Green
$path1="test"
$path2="test1"
Write-Host "Path one is " $path1
Write-Host "Path two is" $path2
Write-Host "Combined path is" -ForegroundColor Green
Join-Path -Path $path1 -ChildPath $path2

Output:

PowerShell Join-Path 1

Parameters:

  • -AdditionalPath: The datatype of this parameter is String[]. This represents the extra values that need to be added to the path. Even though this parameter is optional and specified, the child path parameter must be presented with a value. An indefinite number of paths can be joined using this parameter. The position of this parameter in the cmdlet is 2. None is the default value of this parameter. It accepts pipeline input, but this parameter does not support wildcard characters.
  • -ChildPath: This parameter is mandatory. This represents a value that will be appended with the path parameter’s value. Its position in the cmdlet is one. The datatype of this parameter is a string. None is its default value. It accepts both wildcard characters and pipeline input.
  • -Credential: This parameter is used only for impersonation purpose. The datatype is of PSCredential, and it’s an optional one. The default value is none. This can accept pipeline input, whereas wild card characters are not allowed.
  • -Path: This represents the main path value to which the child paths will be appended. This is a mandatory parameter. The datatype is String[], and its alias is PSPath. The position of this parameter inside the cmdlet is 0. The default value is none. It accepts both pipeline input, and wild card characters are also permitted.
  • -Resolve: This denotes to the cmdlet that the current provider should be used to resolve the joined path. In case if wild cards are supplied the cmdlet returns all the path that aligns with the joined path. If wildcards are not used, in case of no match, an error is thrown. The datatype of this parameter is a switch. This is an optional parameter. The default value is none. It doesn’t accept pipeline input and wild card characters.

Examples of PowerShell Join-Path

Given below are the examples of PowerShell Join-Path:

Example #1

Joining one parent path and one child path.

Code:

Write-Host "Welcome to the demo of joining one parent and one child path" -ForegroundColor Green
$parentpath=Read-Host "Enter the parent path"
$childpath= Read-Host "Enter the child path"
Write-Host "Combined path is as follows" -ForegroundColor Green
Join-Path -Path $parentpath -ChildPath $childpath

Output:

PowerShell Join-Path 2

Example #2

Display contents of the combined path using resolve and wild card characters.

Code:

Write-Host "Demo of using resolve parameter" -ForegroundColor Green
Write-Host "Demo of providing wild card matches in both parent and child" -ForegroundColor Green
$parent= Read-Host "Enter the parent path with wildcard"
$childp= Read-Host "Enter the child path with wildcard"
Write-Host "Display the contents using the join-path" -ForegroundColor Green
Join-Path $parent $childp -Resolve

Output:

resolve and wild card characters

In the above example, the parent path is provided with a value c:\vignesh\t*, which means inside the Vignesh folder, whatever subfolder that starts with t is considered as parent value in the child path “*” is given, which denotes everything. Hence the output is a display of a list of all files that matches the condition.

Example #3

Usage of Additional Path Parameter.

Code:

Write-Host "Welcome to demo of additional child path in Join-path" -ForegroundColor Green
$mainpath= Read-Host "Enter the main path value"
$cpath= Read-Host "Enter the child path value"
$apath1= Read-Host "Enter the additional path one"
$apath2 = Read-Host "enter the additional path two"
$apath3 = Read-Host "enter the additional path three"
$apath4 = Read-Host "enter the additional path four"
$apath5 = Read-Host "enter the additional path five"
Write-Host "Joining all the path" -ForegroundColor Green
$path = Join-Path -Path $mainpath -ChildPath $cpath -AdditionalChildPaths($apath1, $apath2,$apath3,$apath4,$apath5)
Write-Host "the joined path is" -ForegroundColor Green

Output:

Usage of Additional Path Parameter

To find the list of providers supported by this cmdlet, we can run the get-psprovider cmdlet to identify those.

The below are the providers that are supported in the current session:

PowerShell Join-Path 5

PowerShell Join-Path 6

Example #4

Joining multiple paths using the pipeline.

Code:

Write-Host "Welcome to demo of joining path using pipeline input" -ForegroundColor Green
$mainpath= Read-Host "Enter the main path value"
$cpath= Read-Host "Enter the child path value"
$apath1= Read-Host "Enter the additional path one"
$apath2 = Read-Host "enter the additional path two"
$apath3 = Read-Host "enter the additional path three"
$apath4 = Read-Host "enter the additional path four"
$apath5 = Read-Host "enter the additional path five"
Write-Host "Joining all the path using pipeline input" -ForegroundColor Green
Join-Path $mainpath | Join-Path -ChildPath $cpath | Join-Path -ChildPath $apath1 | Join-Path -ChildPath $apath2 | Join-Path -ChildPath $apath3 | Join-Path -ChildPath $apath4 | Join-Path -ChildPath $apath5

Output:

Joining multiple paths using pipeline

While joining, in the above cmdlet, if the child path parameter is specified, an error saying the cmdlet doesn’t accept pipeline input will be thrown. For that to not happen, from the second path, all the paths must be preceded with the child path parameter.

Conclusion

Thus, the article covered details about the Join-Path cmdlet and its various mandatory and optional parameters. It also showed with various examples of concatenation paths in different ways using the Join-Path cmdlet.

Recommended Articles

This is a guide to PowerShell Join-Path. Here we discuss the introduction and examples of PowerShell Join-Path for better understanding. You may also have a look at the following articles to learn more –

  1. PowerShell Sleep
  2. PowerShell SubString
  3. PowerShell not like
  4. Else If in PowerShell
ADVERTISEMENT
MICROSOFT POWER BI Course Bundle - 8 Courses in 1
34+ Hours of HD Videos
8 Courses
Verifiable Certificate of Completion
Lifetime Access
4.5
ADVERTISEMENT
CYBER SECURITY & ETHICAL HACKING Course Bundle - 13 Courses in 1 | 3 Mock Tests
64+ Hours of HD Videos
13 Courses
3 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.5
ADVERTISEMENT
MICROSOFT AZURE Course Bundle - 15 Courses in 1 | 12 Mock Tests
63+ Hour of HD Videos
15 Courses
12 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.5
ADVERTISEMENT
KALI LINUX Course Bundle - 6 Courses in 1
20+ Hours of HD Videos
6 Courses
Verifiable Certificate of Completion
Lifetime Access
4.5
Primary Sidebar
Footer
Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
  • Blog as Guest
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2023 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

🚀 Cyber Monday Reloaded Price Drop! All in One Universal Bundle (3700+ Courses) @ 🎁 90% OFF - Ends in ENROLL NOW