Reputation: 1
I need to create the Body as below but the single quotation mark around ABC gets syntax error when running in PowerShell.
$Body = '{
“Tag”:"Reference='ABC'"
}'
Write-Host -Message "$Body"
I tried the below solution:
$MyVar = 'BRO001023'
$Body = '{
“Tag”:"Reference=$MyVar"
}'
Write-Host -Message "$Body"
BUT I got the result as below.
{
“Filter”:"Reference=$MyVar"
}
How can I make it shows like { “TagFilter”:"Reference='ABC'" }
Upvotes: 0
Views: 236
Reputation: 174445
You can either use a verbatim/single-quoted here-string:
$Body = @'
{
"Tag":"Reference='ABC'"
}
'@
Or escape all inline '
's by doubling them:
$Body = '{
"Tag":"Reference=''ABC''"
}'
See the about_Quoting_Rules
help topic for more information about quoting rules for different string literals
Upvotes: 1