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

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap