how do i get the elements of the two arrays below to appear on separate lines in the here-string, instead of all on one line?
$array1 = @("this","that","the other")
$array2 = @("one","two","three")
$herestring = @"
array1 says
$array1
array2 says
$array2
"@
" "
"array1 says"
$array1
" "
"array2 says"
$array2
" "
"herestring says"
$herestring
array1 says
this
that
the other
array2 says
one
two
three
herestring says
array1 says
this that the other
array2 says
one two three
turning the array into a string with join backtick n also doesn’t workdoes work after all.
$array1 = @("this","that","the other")
$array2 = @("one","two","three")
$array1string = $array1 -join "`n"
$herestring = @"
array1string says
$array1string
array2 says
$array2
"@
" "
"array1string says"
$array1string
" "
"array2 says"
$array2
" "
"herestring says"
$herestring
$array = 1,2,3
"$array"
"And"
$array
arrrays when wrapped in double quotes will automatically gets joined by $OFS, which is an automatic variable which defaults to ’ '.
One method:
$array1 = @("this","that","the other")
$array2 = @("one","two","three")
$herestring = @"
array1string says
$($array1 -join [environment]::NewLine)
array2 says
$($array2 -join [environment]::NewLine)
"@
$herestring
Would also mention this appears you are writing a message for email, which then you should be looking at HTML (ConvertTo-HTML) and not plain text in a here string.