In my years of PowerShell scripting, I’ve often needed to combine strings while ensuring proper spacing between them.
Whether you’re building filenames, creating log messages, or generating reports, you will require string concatenation in PowerShell.
In this tutorial, we will see various methods to concatenate strings with spaces in PowerShell with examples.
Let’s get started with some practical examples that you can apply to your own scripts right away.
Method 1 – Using the Plus (+) Operator
The plus operator is the most straightforward way to concatenate strings in PowerShell.
Here’s how to use it to combine strings with spaces:
$firstName = "John"
$lastName = "Smith"
# Concatenation with explicit space
$fullName = $firstName + " " + $lastName
Write-Host $fullName
# Output: John SmithWhen working with the plus operator, you need to explicitly add the space as a string literal (" "). This gives you precise control over spacing, but can become cumbersome with multiple strings.
Here is the output in the screenshot below:

I often use this method for simple concatenations where readability is more important than efficiency.
Check out Concatenate String and Variable in PowerShell
Method 2 – Using String Interpolation
String interpolation (also called variable expansion) is my preferred method for most scenarios as it’s more readable and efficient. Here is an example.
$firstName = "John"
$lastName = "Smith"
# Basic string interpolation
$fullName = "$firstName $lastName"
Write-Host $fullName
# Output: John SmithThis approach is cleaner because you can embed variables directly within the string. The spaces between variables are preserved exactly as written in the double quotes.
Here is the exact output in the screenshot below:

For more complex expressions, you can use subexpression syntax:
$order = 10
$item = "coffee"
$price = 4.99
# Using subexpressions for formatting
$message = "Your order of $order ${item}s costs $($order * $price) dollars."
Write-Host $message
# Output: Your order of 10 coffees costs 49.9 dollars.The $() syntax allows you to include expressions and formatting inside your strings, which is incredibly powerful.
Read Concatenate String with NewLine in PowerShell
Method 3 – Using the -join Operator
The -join operator in PowerShell is specifically designed for concatenation and offers great flexibility. Here is an example: you can use the -join operator to concatenate a string with a space.
$parts = @("PowerShell", "is", "awesome")
# Join with spaces
$sentence = $parts -join " "
Write-Host $sentence
# Output: PowerShell is awesomeYou can see the exact output in the screenshot below:

You can join array elements with any delimiter:
$path = @("C:", "Users", "JohnSmith", "Documents") -join "\"
Write-Host $path
# Output: C:\Users\JohnSmith\DocumentsI find -join particularly useful when working with arrays or when I need to join a large number of strings with the same delimiter.
Check out Concatenate Strings Inside Loops in PowerShell
Method 4 – Using StringBuilder for Performance
When concatenating many strings in a loop, using the StringBuilder class from .NET can significantly improve performance:
$sb = [System.Text.StringBuilder]::new()
$names = @("Alice", "Bob", "Charlie", "David")
foreach ($name in $names) {
# Append with space
[void]$sb.Append($name)
[void]$sb.Append(" ")
}
# Convert to string and trim the trailing space
$result = $sb.ToString().TrimEnd()
Write-Host $result
# Output: Alice Bob Charlie DavidFor a more controlled approach with spaces:
$sb = [System.Text.StringBuilder]::new()
$names = @("Alice", "Bob", "Charlie", "David")
for ($i = 0; $i -lt $names.Count; $i++) {
[void]$sb.Append($names[$i])
# Add space only if not the last element
if ($i -lt $names.Count - 1) {
[void]$sb.Append(" ")
}
}
$result = $sb.ToString()
Write-Host $result
# Output: Alice Bob Charlie DavidI typically use StringBuilder when concatenating strings inside loops that iterate thousands of times, as it prevents the memory fragmentation that can occur with repeated string concatenation.
Read Concatenate String and Integer in PowerShell
Comparing the Methods: When to Use Each Approach
Here’s a quick reference table to help you choose the right method for your specific scenario:
| Method | Best For | Performance | Readability |
|---|---|---|---|
| + Operator | Simple concatenations | Low for many operations | Good |
| String Interpolation | Most everyday scenarios | Good | Excellent |
| -join Operator | Arrays and collections | Excellent | Very Good |
| StringBuilder | Large loops and performance-critical code | Excellent | Fair |
Special Cases
Here are some special cases that you might face while concatenating a string with a space.
Working with Different Data Types
PowerShell automatically converts many data types to strings during concatenation:
$quantity = 5
$product = "chairs"
$price = 49.99
# Mixing strings and numbers
$orderSummary = "Order: $quantity $product at $" + $price + " each"
Write-Host $orderSummary
# Output: Order: 5 chairs at $49.99 eachFormatting Numbers and Dates
For more control over number and date formatting, use the -f operator:
$total = 1234.56789
$date = Get-Date
# Format specifiers with the -f operator
$receipt = "Purchase total: {0:C2} on {1:MM/dd/yyyy}" -f $total, $date
Write-Host $receipt
# Output example: Purchase total: $1,234.57 on 06/04/2023Multi-line String Concatenation
For readability in complex scripts, you can break concatenation across lines:
$address = $streetNumber + " " +
$streetName + ", " +
$city + ", " +
$state + " " +
$zipCode
# Or with string interpolation (my preference)
$address = "$streetNumber $streetName,
$city,
$state $zipCode"I hope this tutorial, you learned how to concatenate strings with spaces in PowerShell. Each method has its advantages, and choosing the right one depends on your specific scenario.
If you have any questions or suggestions, please feel free to share them in the comments below.
You may also like:
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.