EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • 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 string
 

PowerShell join string

Updated March 4, 2023

PowerShell join string

 

 

Introduction to PowerShell join string

PowerShell Join String (method of a .NET string class) which combines multiple strings and generates a single string in the same order as the input was provided and the Join-String method has been added to the new PowerShell core version and it supports the advance Join method for the PowerShell String.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

Syntax

-Join <String[]>
<String[]> -Join <Delimiter>

Join-String Syntax,

Join-String
[[-Property] <PSPropertyExpression>] [[-Separator] <String>] [-OutputPrefix <String>] [-OutputSuffix <String>] [-UseCulture] [-InputObject <PSObject[]>] [<CommonParameters>]

Join-Path syntax,

Join-Path
[-Path] <String[]>
[-ChildPath] <String>
[[-AdditionalChildPath] <String[]>] [-Resolve] [-Credential <PSCredential>] [<CommonParameters>]

How does the PowerShell Join string works?

PowerShell Join command works on the String to concatenate the multiple strings into one. In the syntax of Join,

-Join <String[]>
<String[]> -Join <Delimiter>

String[] – Indicates the multiple string inputs.

<Delimiter> – Indicates the strings to join with. If no delimiter is provided, -Join command by default concatenate the string with (“ ”).

For example,

-Join ("Hello","PoweShell","Join")

Output:

PowerShell join string output 1

You might have noticed that we have used string inside the brackets because the string with a round bracket mentions the array and if we don’t use it and if there is a comma (,) separator between them then only the first string will be submitted to the Join operator. See the example below,

-Join "Hello","PoweShell","Join"

Output:

PowerShell join string output 2

You can also use the variable to concatenate the string.

$var = "Hello","PoweShell","Join"
-Join $var

Output:

PowerShell join string output 3

This -Join String method works with any version of the PowerShell (Framework or Core version).

There is another method called Join-String which does the same multiple strings joining operations but it has some advanced methods like we can apply a formula for a substring, we can use splatting, use different parameters for separators after joining the script like SingleQuote or DoubleQuote or we can create a class definition from an object.

This method works only with PowerShell Core (6.2 or above version).

If you don’t specify any properties and use directly Join-String command, it will use $OFS (Output Field Separator ) and by default it is “ ”.

For example,

"Hello","PowerShell","Join" | Join-String

Output:

PowerShell join string output 4

There is also the command Join-Path which joins the parent and the child’s path.

Examples

Here are the following examples mention below

1. Multiple ways to use the -Join string command.

Without using Array,

-Join "Animals","Birds","Vehicles"

Output:

PowerShell join string output 5

With using an array,

-Join ("Animals","Birds","Vehicles")

Output:

PowerShell join string output 6

With using a variable,

$a =  "Hello","PowerShell","Join"
-Join $a

Output:

PowerShell join string output 7

2. Join String with a specific delimiter.

To join a string with a specific delimiter, we need to use use the command as shown in the syntax and the example is shown below.

Example #1

"Hello","PowerShell","Join" -join ','

Output:

PowerShell join string output 8

Example #2

"PowerShell","Azure","Runbook" -join " "

Output:

PowerShell join string output 9

Example #3

In the below example, we are using characters to join the string.

"PowerShell","Azure","Runbook" -join "#O"

Output:

PowerShell join string output 10

You can also directly apply the Join operation to the cmdlet. For example, the below command will get the content from a text file and joins them with a semicolon (;).

(Get-Content C:\Temp\Servers.txt) -join ';'

Output:

PowerShell join string output 11

3. Join-Path command.

To join the child and parent path,

Join-Path -Path C:\ -ChildPath 'temp'

Output:

PowerShell join string output 12

When we use the ‘\’ in the path that is ignored as shown below.

Join-Path -Path 'C:\' -ChildPath '\temp'

Output:

PowerShell join string output 13

4. Join-String command.

As discussed above, this command provides advanced functionality to Join multiple strings. For example,

Example1: Default Separator of Join-String command.

"PowerShell","Azure","runbook" | Join-String

Output:

output 14

In the above example, strings are joined with $OFS.

Example2: Join-String command with separator.

"PowerShell","Azure","runbook" | Join-String -Separator ','

Output:

output 15

Example #3 – Join-String with a Separator and -SingleQuote property.

"PowerShell","Azure","runbook" | Join-String -Separator ',' -SingleQuote

Output:

output 16

Example #4 – Join-String with a Separator and -DoubleQuote property.

"PowerShell","Azure","runbook" | Join-String -Separator ',' -DoubleQuote

Output:

output 17

Example #5 – Get-Process with Join-String.

In the below example, we are joining the first 5 processes with the property “Name” with the separator and using the double quote.

Get-Process | Select -First 5 | Join-String -Property Name -Separator ',' -DoubleQuote

Output:

output 18

Here, the Get-Process which retrieves the list of the running processes is passed through the pipeline to the Join-String command, and Property “Name” is used to join. You can select different properties like process ID as well.

Get-Process | Select -First 5 | Join-String -Property id -Separator ','

Output:

output 19

Example #6 – Using a property name with SubString operation to Join Process names.

In the below example, we will use the substring operation to Join processes with the first 3 characters.

Get-Process | Select -First 5 | Join-String -Property {$_.Name.Substring(0,3)} -Separator ',' -DoubleQuote

Output:

output 20

In the below example, we are selecting the first 5 processes, passing it to the Name property of the Join-String command, and then converting it into Caps and joins.

Get-Process | Select -First 5 | Join-String -Property {$_.Name.ToUpper()} -Separator ',' -DoubleQuote

Output:

output 21

Example #7 – Separator with Special characters.

As a separator, we can also use special characters. A list of special characters you can get from the MS link below.

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_special_characters?view=powershell-7.1

The below command will retrieve the processes starting with “Power” and join them with its “Name” property and separate them with a special character `n (New Line) and `t (tab) and labeled the output as “PowerShell Processes” and -OutPrefix parameter used for it.

Get-Process Power* | Join-String -Property Name -Separator "`n`t" -OutputPrefix "PowerShell Processes: `n`t"

Output:

output 22

Please note: We have added special characters at the end of the line so the first line will be formatted accordingly.

Conclusion

PowerShell Join commands are extremely helpful in the script when we are working with the strings and useful when we are working with paths so we can join the path and can also perform the join operation on the split string.

 Recommended Articles

This is a guide to PowerShell join string. Here we discuss How does the PowerShell Join string works along with the examples and outputs. You may also have a look at the following articles to learn more –

  1. PowerShell Boolean
  2. PowerShell SubString
  3. PowerShell Filter
  4. PowerShell Count

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

© 2025 - 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
EDUCBA

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

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 Login

Forgot Password?

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

🚀 Limited Time Offer! - ENROLL NOW