EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login
Home Data Science Data Science Tutorials PowerShell Tutorial PowerShell join string
Secondary 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 Start-Service
    • PowerShell is not digitally signed
    • PowerShell Uptime
    • PowerShell Create Directory
    • 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 Restart Service
    • PowerShell comment
    • PowerShell Map Network Drive
    • PowerShell Append to File
    • PowerShell print
    • What is PowerShell
    • Uses Of Powershell
    • PowerShell Empire
    • PowerShell Parameter
    • PowerShell Stop Service
    • PowerShell Versions
    • How To Install PowerShell
    • PowerShell uninstall module
    • How to Use PowerShell?
    • PowerShell Logging
    • PowerShell Tools
    • PowerShell Commands
    • PowerShell Version Command
    • 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

PowerShell join string

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.

Syntax

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

Join-String Syntax,

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

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

All in One Data Science Bundle(360+ Courses, 50+ projects)
Python TutorialMachine LearningAWSArtificial Intelligence
TableauR ProgrammingPowerBIDeep Learning
Price
View Courses
360+ Online Courses | 50+ projects | 1500+ Hours | Verifiable Certificates | Lifetime Access
4.7 (86,354 ratings)

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
Popular Course in this category
PowerShell Training (2 Courses, 1 Project)
  2 Online Courses |  1 Hands-on Project |   4+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course

Related Courses

Shell Scripting Training (4 Courses, 1 Project)4.9
All in One Data Science Bundle (360+ Courses, 50+ projects)4.8
Data Visualization Training (15 Courses, 5+ Projects)4.7
0 Shares
Share
Tweet
Share
Primary Sidebar
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

ISO 10004:2018 & ISO 9001:2015 Certified

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

EDUCBA
Free Data Science Course

SPSS, Data visualization with Python, Matplotlib Library, Seaborn Package

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

Forgot Password?

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.

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.

Let’s Get Started

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

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more