A single-quote delimited string will not expand variables:
$SomeVar="SomeVal"
Write-Host 'Value is $SomeVar'
#Outputs Value is $SomeVar
A double-quoted string will expand variables:
$SomeVar="SomeVal"
Write-Host "Value is $SomeVar"
#Outputs Value is SomeVal
To expand an expression use $(expression)
within a double-quoted string
$SomeVar="SomeVal"
Write-Host "Value is $($SomeVar.ToUpper())"
#Outputs Value is SOMEVAL
To show double-quotes in a double-quoted string use backticks (Also used to create escape sequences, e.g. `r, `n)
$SomeVar="SomeVal"
Write-Host "Value is `"$SomeVar`""
#Outputs Value is "SomeVal"
To preserve formatting and use multiple lines (e.g. to create JSON) use a here string.
Here strings must start and end with @"
and "@
on individual lines respectively:
$SomeVar="SomeVal"
Write-Host @"
Value is
"$SomeVar"
"@
#Outputs
#Value is
# "SomeVal"
[
powershell
]