Powershell Formatting for a String

The reason your current attempt doesn’t work is that single-quoted (') string literals in PowerShell are verbatim strings – no attempt will be made at expanding subexpression pipelines or variable expressions.

If you want an expandable string literal without having to escape all the double-quotes (") contained in the string itself, use a here-string:

$mynumber = 2

$tag = @"
{"number" = "$($mynumber)", "application" = "test","color" = "blue", "class" = "Java"}
"@

Leave a Comment