Forum Discussion
Buutenlander
Apr 14, 2022Copper Contributor
output in mail is a single line
Hi all, I would like to pipe output form any *GET* command to mail as body. That works alright, but instead of getting a nicely formatted table of records i get a single line of text. ${*Us...
LainRobertson
Apr 14, 2022Silver Contributor
First, an observation.
Using -BodyAsHtml is a mistake in your script's current form, as the body's not HTML at all but simply a plain-text string.
This leads to having two options you can pursue:
- Add tags around your existing string (the $Result variable), or;
- Leave the -BodyAsHtml out.
For Option 1, you can introduce the tags you need using ConvertTo-Html instead of Out-String:
$Username = Read-Host -Prompt 'Type username'
$Result = Get-ADPrincipalGroupMembership $Username | select Name | ConvertTo-Html
Send-MailMessage -From Email address removed -Subject memberships -To Email address removed -Body $Result -BodyAsHtml -SmtpServer smtp.mydomain.com
Option 2 doesn't really need further explanation, though you may or may not need to fiddle with the -Encoding parameter depending on your environment.
Cheers,
Lain