Powershell

How to concatenate string in powershell?

How to concatenate string in powershell?

 

1. Concatenate string Use -join

$var = -join(“Hello”, ” “, “world”);

Stores  “Hello world” to $var.

So to output, in one line:

Write-Host (-join(“Hello”, ” “, “world”))

2. Concatenate string using “-“

Write-Host “$($products.Id) – $($products.Name) – $($products.Owner)”

3. Concatenate string using indirectly with “-“

Write-Host (“{0} – {1} – {2}” -f $products.Id,$products.Name,$products.Owner )
Or just (but I don’t like it 😉 ):

Write-Host $products.Id ” – ” $products.Name ” – ” $products.Owner

 

4. Concatenate string using “+”

$string = $products.ID
$string += ” – ”
$string += $products.Name
$string += ” – ”
$string += $products.Owner
Write-Host $string

1. Best easy method to Concatenate string

Write-Host “$($products.Id) – $($products.Name) – $($products.Owner)”

 

I will add more ways for below soon and comment you would like to be soon rather than later

 

  1. concatenate string in loop powershell
  2. concatenate two strings in powershell script
  3. concatenate strings in array powershell
  4. concatenate string and date in powershell
  5. concatenate string and integer in powershell
  6. powershell concatenate string in select-object
  7. concatenate a string in powershell
  8. powershell concatenate string in argument
Vamshi B

Recent Posts

How to install Firefox browser using Powershell

How to install of FireFox browser using PowerShell Sometimes you would like to install Firefox…

2 years ago

How to install chrome with Powershell?

Quick way to install chrome on windows with Powershell? Launch the Powershell and run below…

2 years ago

How to Fix PowerShell Script Not Digitally Signed Error?

How to Fix PowerShell Script Not Digitally Signed Error? When a script with a .ps1…

2 years ago

Powershell Cheat Sheet for beginners

Powershell Cheat Sheet for beginners PowerShell has become something of an ace in the hole…

3 years ago

Can you use Linux commands in Powershell?

Today we discuss one of a few questions a lot of sysadmins and IT Admins…

3 years ago

Backing Up an SQL Database with PowerShell

Backing Up an SQL Database with PowerShell Before making any changes in the production environment,…

3 years ago

This website uses cookies.