Use the "-join" operator:
$Input = 1,2,3,4
$body = ($input -join [Environment]::NewLine) + [Environment]::NewLine
You can substitute "r
n" for "[Environment]::NewLine" if you like.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I load some information in from a file which is of the format
User1
User2
etc
using $Input = Get-Content "StaticUsers.txt"
At the end of my script I send an email with the body being sent to a number of users using
$body = "$Input" + "r
n"
The issue is that the received email shows the list as the following
User1 User2 etc
instead of each item on a new line. How can I achieve this?
Use the "-join" operator:
$Input = 1,2,3,4
$body = ($input -join [Environment]::NewLine) + [Environment]::NewLine
You can substitute "r
n" for "[Environment]::NewLine" if you like.
Hello
Thank you for your question and reaching out.
The PowerShell newline indicator is n, and can only be used in double quotes. Single quotes will print the actual "n".
For Example :
$body = "first line" + "`n" + "second line"
Also, One solution would be to use <br /> to break lines and specify the switch -BodyAsHtml so that body would be treated as html and email client would display it correctly, alternatie approach would be to use `n for line breaks and keep body as text.
--If the reply is helpful, please Upvote and Accept as answer--