0

I am looking for away to load a variable with a combination of text and content of other vars, but in separate lines. i.e.

$a=text1
$b=text2
$c = "text"
(line2) $a
(line3) $b

So in $c i would like to store $a and $b plus some text in different lines and show it up with write-host

'write-host $c'

i tried

$c=@'
this is line1
line2: contains $a
line3: contains $b
@'

but instead of the value of the vars I get $a, $b etc```
mklement0
  • 382,024
  • 64
  • 607
  • 775
ChrKuznos
  • 15
  • 2
  • 4
  • Does this answer your question? [string variable not substituted in multi-line string](https://stackoverflow.com/questions/28291678/string-variable-not-substituted-in-multi-line-string) – Paolo Apr 03 '23 at 08:22
  • Quoting in PowerShell is like ksh/bash/etc. Strings enclosed in QUOTATION MARK characters get interpolated. Strings enclosed in APOSTROPHE characters are as-is, without interpolation. – lit Apr 03 '23 at 13:41

1 Answers1

3

The correct and working script is the following:

$a = "text1"
$b = "text2"
$c = @"
this is line1
line2: contains $a
line3: contains $b
"@

Write-Host $c

You must use double quotes and the @ character is in a wrong place in your script.

Kapitany
  • 1,319
  • 1
  • 6
  • 10