0

This is what I have (the addresses are hard coded but I want to use variables for dynamic):

Set-Content -LiteralPath $test -NoNewLine -Value (
  @'
From:
hardcodedAddress1
hardCodedZip1
'@ + (Get-Content -Raw test)
)

The code below doesn't work.

Set-Content -LiteralPath $test -NoNewLine -Value (
  @'
From:
$address1
$zip1
'@ + (Get-Content -Raw test)
)

Anyone know how to get it working with variables? Edit1: $test is my path to a csv file

mklement0
  • 382,024
  • 64
  • 607
  • 775
  • @AbrahamZinala sorry, thats my error when writing. Its just $test which has the path ending with .csv – Milan Patel Jun 18 '21 at 15:49
  • 2
    You just need to change `@'...'@` to `@"..."@` to allow variable expansion. – Santiago Squarzon Jun 18 '21 at 15:50
  • 1
    The title says`Csv`, but what you apparently want is nothing like csv... – Theo Jun 18 '21 at 17:54
  • In short: Only `"..."` strings (double-quoted) perform string interpolation in PowerShell, not `'...'` strings (single-quoted) - this applies to the here-string variants too: see [this answer](https://stackoverflow.com/a/40445998/45375) for an overview of PowerShell's _expandable strings_ (string interpolation) and [this answer](https://stackoverflow.com/a/55614306/45375) for an overview of PowerShell string literals in general. – mklement0 Jun 18 '21 at 18:05

0 Answers0