07-21-2023, 10:55 AM
Suppose I have the following snippet:
<!-- language: lang-powershell -->
$assoc = New-Object PSObject -Property @{
Id = 42
Name = "Slim Shady"
Owner = "Eminem"
}
Write-Host $assoc.Id + " - " + $assoc.Name + " - " + $assoc.Owner
I'd expect this snippet to show:
> `42 - Slim Shady - Eminem`
But instead it shows:
> `42 + - + Slim Shady + - + Eminem`
Which makes me think the `+` operator isn't appropriate for concatenating strings and variables.
How should you approach this with PowerShell?
<!-- language: lang-powershell -->
$assoc = New-Object PSObject -Property @{
Id = 42
Name = "Slim Shady"
Owner = "Eminem"
}
Write-Host $assoc.Id + " - " + $assoc.Name + " - " + $assoc.Owner
I'd expect this snippet to show:
> `42 - Slim Shady - Eminem`
But instead it shows:
> `42 + - + Slim Shady + - + Eminem`
Which makes me think the `+` operator isn't appropriate for concatenating strings and variables.
How should you approach this with PowerShell?