If you are working with strings in PowerShell, then you might want to concatenate strings. In this PowerShell tutorial, I will show you different methods to concatenate strings in PowerShell. We will see how to combine multiple strings into a single string using PowerShell.
To concatenate strings in PowerShell, you can use the + operator. For example, “John” + ” ” + “Doe” will yield “John Doe”. Another method is using the -f format operator, such as “{0} {1}” -f “John”, “Doe”. Also the Join-String cmdlet can be used for more complex concatenation tasks. Here’s a simple example:
$firstName = "John"
$lastName = "Doe"
$fullName = $firstName + " " + $lastName
Write-Host $fullName # Outputs: John DoeConcatenate Strings in PowerShell
To combine strings in PowerShell, we can use the below methods:
- Using the + Operator
- Using the -f Operator (Format Operator)
- Using String Interpolation
- Using the -join Operator
- Using the String.Concat() Method
- Using the StringBuilder Class
We will check all the above methods with examples.
1. Using the + Operator
The simplest way to concatenate strings in PowerShell is to use the + operator. This cmdlet is very simple and looks like the one below.
Here is a complete PowerShell script.
$city1 = "New York"
$city2 = "Los Angeles"
$city3 = "Chicago"
$combinedCities = $city1 + ", " + $city2 + ", " + $city3
Write-Output $combinedCitiesOutput:
New York, Los Angeles, ChicagoYou can see the output in the screenshot below after I executed the PowerShell script using VS code.

Read Concatenate Strings Inside Loops in PowerShell
2. Using the -f Operator (Format Operator)
The -f operator in PowerShell allows for more complex string formatting. It is similar to string interpolation in other languages.
Here is a complete PowerShell script.
$city1 = "Houston"
$city2 = "Phoenix"
$city3 = "Philadelphia"
$combinedCities = "{0}, {1}, {2}" -f $city1, $city2, $city3
Write-Output $combinedCitiesOutput:
Houston, Phoenix, PhiladelphiaYou can see the output in the screenshot below; I executed the script.

3. Using String Interpolation
String interpolation embeds variable values directly within a string in PowerShell. In PowerShell, you can use double quotes (") to achieve this.
Here is a complete script to merge strings in PowerShell.
$city1 = "San Antonio"
$city2 = "San Diego"
$city3 = "Dallas"
$combinedCities = "$city1, $city2, $city3"
Write-Output $combinedCitiesOutput:
San Antonio, San Diego, DallasYou can see the output in the screenshot below; I executed the PowerShell script.

4. Using the -join Operator
The -join operator can be used to concatenate an array of strings with a specified separator in PowerShell. This is particularly useful when dealing with lists.
$cities = @("San Jose", "Austin", "Jacksonville")
$combinedCities = -join($cities, ", ")
Write-Output $combinedCitiesOutput:
San Jose, Austin, Jacksonville5. Using the String.Concat() Method
The String.Concat method from the .NET framework can also be used to concatenate strings in PowerShell.
Here is a complete PowerShell script.
$city1 = "San Francisco"
$city2 = "Columbus"
$city3 = "Fort Worth"
$combinedCities = [String]::Concat($city1, ", ", $city2, ", ", $city3)
Write-Output $combinedCitiesOutput:
San Francisco, Columbus, Fort WorthYou can see the output in the screenshot below:

6. Using the StringBuilder Class
If you need to concatenate a large number of strings efficiently, then you can use the StringBuilder class in PowerShell.
Below is a complete script for concatenating strings in PowerShell using the StringBuilder Class.
Add-Type -AssemblyName "System.Text"
$stringBuilder = New-Object System.Text.StringBuilder
$cities = @("Indianapolis", "Charlotte", "Seattle")
foreach ($city in $cities) {
[void]$stringBuilder.Append("$city, ")
}
# Remove the trailing comma and space
if ($stringBuilder.Length -gt 0) {
$stringBuilder.Length -= 2
}
$combinedCities = $stringBuilder.ToString()
Write-Output $combinedCitiesOutput:
Indianapolis, Charlotte, SeattleConclusion
I hope this tutorial helps you concatenate 2 strings in PowerShell. In it, I have explained 6 different methods for concatenating strings in PowerShell.
You may also like:
- How to Split String by Tab Character in PowerShell?
- How to Filter Strings in PowerShell?
- How to Split Strings by Newlines in PowerShell?
- Concatenate Strings and Floats in PowerShell
Bijay Kumar is an esteemed author and the mind behind PowerShellFAQs.com, where he shares his extensive knowledge and expertise in PowerShell, with a particular focus on SharePoint projects. Recognized for his contributions to the tech community, Bijay has been honored with the prestigious Microsoft MVP award. With over 15 years of experience in the software industry, he has a rich professional background, having worked with industry giants such as HP and TCS. His insights and guidance have made him a respected figure in the world of software development and administration. Read more.