PowerShell Concatenate String Examples

In PowerShell + is the operator that you need to make use of to concatenate strings.

Let's take a look at a few examples.


Example 1: Using + operator

    $firstName = "Chris"
    $lastName = "Adams"
    
    $name = $firstName + " " + $lastName
    
    Write-Host "Name: $name"

    Chris Adams


Example 2: Using String interpolation

    String interpolation is another way to concatenate Strings in PowerShell.

    $firstName = "Sam"
    $lastName = "Adams"
    $name = "$firstName $lastName"      
    Write-Host $name

    Sam Adams

String Concatination Example PowerShell

Comments & Discussion

Facing issues? Have questions? Post them here! We're happy to help!