powershell concatenate string in select-object

Clear2all Professional Blog new

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

Read the rest