EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login

PowerShell Join-Path

Home » Data Science » Data Science Tutorials » PowerShell Tutorial » PowerShell Join-Path

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.

Syntax of PowerShell Join-Path

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

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

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.

Popular Course in this category
Sale
Shell Scripting Training (4 Courses, 1 Project)4 Online Courses | 1 Hands-on Project | 18+ Hours | Verifiable Certificate of Completion | Lifetime Access
4.5 (8,705 ratings)
Course Price

View Course

Related Courses
All in One Data Science Bundle (360+ Courses, 50+ projects)Data Visualization Training (15 Courses, 5+ Projects)

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

All in One Data Science Bundle (360+ Courses, 50+ projects)

360+ Online Courses

50+ projects

1500+ Hours

Verifiable Certificates

Lifetime Access

Learn More

0 Shares
Share
Tweet
Share
Primary Sidebar
PowerShell Tutorial
  • Functions
    • PowerShell Functions
    • PowerShell String Functions
    • powershell nslookup
    • PowerShell here string
    • PowerShell Wildcards
    • Regex in PowerShell
    • PowerShell not like
    • PowerShell Filter
    • PowerShell Sleep
    • PowerShell where
    • PowerShell join string
    • PowerShell Exit
    • PowerShell null
    • PowerShell Dictionary
    • PowerShell Location
    • PowerShell Trim
    • PowerShell Join-Path
    • PowerShell Execution Policy
    • PowerShell SubString
    • PowerShell Format Table
    • PowerShell Import Module
    • PowerShell ForEach Object
    • PowerShell Alias
    • PowerShell Scheduled Task
    • PowerShell Convert String to Date
    • PowerShell Split String
    • PowerShell Multiline String
    • PowerShell MultiLine Comment
    • PowerShell Rename Folder
    • PowerShell Delete Folder
    • PowerShell String Replace
    • PowerShell join
    • PowerShell xcopy
    • PowerShell Base64
    • PowerShell Tail
    • PowerShell User List
    • PowerShell remove User from group
    • PowerShell JSON Format
    • PowerShell Send Mail
    • PowerShell Convert to String
    • PowerShell Start-Process
    • PowerShell change directory
    • PowerShell Open File
    • PowerShell Batch File
    • PowerShell ZIP
    • PowerShell unzip
    • PowerShell XML
    • PowerShell XML Parsing
    • Remote PowerShell
    • PowerShell Escape Character
    • PowerShell scriptblock
    • PowerShell Executable Location
    • PowerShell Import-CSV?
    • PowerShell Export CSV
  • Basics
    • PowerShell comment
    • PowerShell Map Network Drive
    • PowerShell Append to File
    • PowerShell print
    • What is PowerShell
    • Uses Of Powershell
    • PowerShell Versions
    • How To Install PowerShell
    • PowerShell uninstall module
    • How to Use PowerShell?
    • PowerShell Logging
    • PowerShell Tools
    • PowerShell Commands
    • PowerShell Administrator
    • PowerShell Modules
    • PowerShell Registry
    • PowerShell block Comment
    • PowerShell Verbs
    • PowerShell list
    • PowerShell add user to group
    • PowerShell Write to Console
    • Variable in PowerShell
    • PowerShell New Line
    • PowerShell prompt for input
    • PowerShell File Extension
    • Powershell Remotesigned
    • PowerShell Write to File
    • PowerShell Ping
    • PowerShell wget
    • PowerShell Global variable
    • PowerShell Get-ADGroup
    • Array in PowerShell
    • PowerShell Multidimensional Array
    • PowerShell Array of Strings
    • PowerShell? join array
    • Useful PowerShell Scripts
    • String in PowerShell
    • PowerShell Switch Statement
    • PowerShell Function Parameters
    • PowerShell vs PowerShell ISE
    • PowerShell test-connection
    • PowerShell Test-NetConnection
    • PowerShell GUI
    • PowerShell Variable in String
    • PowerShell Active Directory
  • Variables
    • PowerShell Variables
    • PowerShell Environment Variables
    • PowerShell set environment variable
    • Hashtable in PowerShell
    • Set Variable in PowerShell
  • Operators
    • PowerShell Operators
    • Comparison Operators in PowerShell
    • Logical Operators in PowerShell
    • PowerShell Boolean
    • PowerShell Like Operator
  • cmdlet
    • PowerShell Wait
    • PowerShell Match
    • cmdlets in PowerShell
    • Start PowerShell from cmd
    • Add-Content in PowerShell
    • Get Help in PowerShell
    • PowerShell Copy-Item
    • PowerShell Remove-Item
    • PowerShell Move-Item
    • Get Command in PowerShell
    • PowerShell Run Command
    • Windows PowerShell ISE
    • Windows Powershell Commands
    • WinRM PowerShell
    • PowerShell Date
    • Powershell Write-Host
    • PowerShell Get-ChildItem
    • PowerShell Sort-Object
    • PowerShell Where Object
    • PowerShell Set-Content
    • PowerShell Set-Location
    • PowerShell Invoke-Command
    • PowerShell Invoke-Webrequest
    • PowerShell Get-Location
    • PowerShell Get-Date
    • PowerShell Get-Service
    • PowerShell Test-Path
    • Powershell Module Path
    • PowerShell Out-File
    • PowerShell if File Exists
    • Powershell Copy File
    • PowerShell Delete File
    • PowerShell New-Item
    • PowerShell Rename-Item
    • PowerShell ComputerName
    • PowerShell Get-Content
    • PowerShell Get-Item
    • PowerShell Get-ADUser
    • PowerShell Grep
    • PowerShell Concatenate String
    • PowerShell Get-Process
    • PowerShell Count
    • PowerShell pause
  • Control Statements
    • If Statement in PowerShell
    • If Else in PowerShell
    • Else If in PowerShell
    • Loops in PowerShell
    • For loop in PowerShell
    • PowerShell While Loop
    • PowerShell do while
    • PowerShell Loop through Array
    • PowerShell add to array
    • PowerShell ForEach Loop
    • PowerShell Break
    • PowerShell Continue
    • Switch Case in PowerShell
    • PowerShell If-Not
    • Try-catch in PowerShell
  • Interview Questions
    • PowerShell Interview Questions

Related Courses

Shell Scripting Course

All in One Data Science Courses

Data Visualization Courses

Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

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

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

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

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

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

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

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

Let’s Get Started

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

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA Login

Forgot Password?

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

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

EDUCBA

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

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

Special Offer - Shell Scripting Course Learn More