Search code examples
powershellformattingoutputnewlinecarriage-return

New line for all strings added to one


How can I add all string to one variable with each in new line I have tried all these options but nothing seems to be working *All variable types here are string so thats not the problem

$Body = $alerts[1].description("'n") + $alerts[1].name("'n") + alerts[1].timeadded

$Body = $alerts[1].description "`n" + $alerts[1].name "`n" + $alerts[1].timeadded

$Body = $alerts[1].description `n + $alerts[1].name `n + $alerts[1].timeadded

$Body = $alerts[1].description `n  $alerts[1].name `n $alerts[1].timeadded

I want the output of $body to appear in new line each:

$alerts[1].description
$alerts[1].name
$alerts[1].timeadded

Solution

  • I believe what you're looking for is:

    $Body = $alerts[1].description + "`n" + $alerts[1].name + "`n" + $alerts[1].timeadded
    

    The character `n corresponds to a newline, which should join the strings as you described.