I need to reformat this so it sends output in a column to my email, not a row. It now comes across as a table with 7 horizonal rows. I need it in one column. I tried various formatting options.<\/p>\n
\"EP1\" = $AvailableUnitsE\n\n \"Au\" = $AvailableUnitsP\n\n \"M\" = $AvailableUnitsE2\n\n \"M3\" = $AvailableUnitsE3 \n\n \"Pe\" = $AvailableUnitsPPE\n\n \"Pr\" = $AvailableUnitsPr \n\n \"Vi\" = $AvailableUnitsVi\n\n \n\n \n\n }\n\n \n\n $Header = @\"\n\n <style>\n\n TABLE {border-width: 1px; border-style: solid; border-color: black; border-collapse:\n\n collapse;}\n\n TH {border-width: 1px; padding: 3px; border-style: solid; border-color: black;\n\n background-color: #6495ED;}\n\n TD {border-width: 1px; padding: 3px; border-style: solid; border-color: black;}\n\n </style>\n\n \n\n \"@\n\n \n\n $body = $licenseReport | ConvertTo-Html -head $Header | out-string\n\n \n\n \n\n \n\n $messagereport = @{\n\n subject = \"License Counts\"\n\n Body = $body\n\n From = [email protected]\n\n To = [email protected]\n\n SmtpServer = “10.1.1.1”}\n\n Send-MailMessage @messagereport -BodyAsHtml\n<\/code><\/pre>","upvoteCount":5,"answerCount":10,"datePublished":"2021-11-26T19:28:40.000Z","author":{"@type":"Person","name":"trublucali","url":"https://community.spiceworks.com/u/trublucali"},"suggestedAnswer":[{"@type":"Answer","text":"
Advertisement
I need to reformat this so it sends output in a column to my email, not a row. It now comes across as a table with 7 horizonal rows. I need it in one column. I tried various formatting options.<\/p>\n
\"EP1\" = $AvailableUnitsE\n\n \"Au\" = $AvailableUnitsP\n\n \"M\" = $AvailableUnitsE2\n\n \"M3\" = $AvailableUnitsE3 \n\n \"Pe\" = $AvailableUnitsPPE\n\n \"Pr\" = $AvailableUnitsPr \n\n \"Vi\" = $AvailableUnitsVi\n\n \n\n \n\n }\n\n \n\n $Header = @\"\n\n <style>\n\n TABLE {border-width: 1px; border-style: solid; border-color: black; border-collapse:\n\n collapse;}\n\n TH {border-width: 1px; padding: 3px; border-style: solid; border-color: black;\n\n background-color: #6495ED;}\n\n TD {border-width: 1px; padding: 3px; border-style: solid; border-color: black;}\n\n </style>\n\n \n\n \"@\n\n \n\n $body = $licenseReport | ConvertTo-Html -head $Header | out-string\n\n \n\n \n\n \n\n $messagereport = @{\n\n subject = \"License Counts\"\n\n Body = $body\n\n From = [email protected]\n\n To = [email protected]\n\n SmtpServer = “10.1.1.1”}\n\n Send-MailMessage @messagereport -BodyAsHtml\n<\/code><\/pre>","upvoteCount":5,"datePublished":"2021-11-26T19:28:40.000Z","url":"https://community.spiceworks.com/t/powershell-output-to-email-formatting-to-column/818076/1","author":{"@type":"Person","name":"trublucali","url":"https://community.spiceworks.com/u/trublucali"}},{"@type":"Answer","text":"
Advertisement
I think you messed up the formatting of the script. The start is NOT Powershell syntax??<\/p>","upvoteCount":0,"datePublished":"2021-11-26T19:39:28.000Z","url":"https://community.spiceworks.com/t/powershell-output-to-email-formatting-to-column/818076/2","author":{"@type":"Person","name":"DoctorDNS","url":"https://community.spiceworks.com/u/DoctorDNS"}},{"@type":"Answer","text":"
Also<\/p>\n
SmtpServer = “10.1.1.1”}\n<\/code><\/pre>\nwill fail. Try:<\/p>\n
SmtpServer = \"10.1.1.1\"}\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2021-11-26T19:40:53.000Z","url":"https://community.spiceworks.com/t/powershell-output-to-email-formatting-to-column/818076/3","author":{"@type":"Person","name":"DoctorDNS","url":"https://community.spiceworks.com/u/DoctorDNS"}},{"@type":"Answer","text":"The PS script currently works fine. I just need to have it format into a column, not a row.<\/p>","upvoteCount":0,"datePublished":"2021-11-26T20:23:34.000Z","url":"https://community.spiceworks.com/t/powershell-output-to-email-formatting-to-column/818076/4","author":{"@type":"Person","name":"trublucali","url":"https://community.spiceworks.com/u/trublucali"}},{"@type":"Answer","text":"
The script you posted is missing stuff at the beginning.<\/p>\n
¿Where is $licensereport<\/em> defined?<\/p>","upvoteCount":0,"datePublished":"2021-11-26T21:30:11.000Z","url":"https://community.spiceworks.com/t/powershell-output-to-email-formatting-to-column/818076/5","author":{"@type":"Person","name":"tulioarends","url":"https://community.spiceworks.com/u/tulioarends"}},{"@type":"Answer","text":"It sounds like you want to manually include the line breaks, or the carriage returns.<\/p>\n
This would simply be “text for entire line” + $maybe variable + <\/p>\n
n (backtick with letter n) is the line break I believe, so you can put it at the end of each line + \"<\/code>n\"<\/p>\nlike that…!<\/p>\n
Hope that helps,<\/p>\n
Jeff Cummings<\/p>","upvoteCount":0,"datePublished":"2021-11-26T21:39:26.000Z","url":"https://community.spiceworks.com/t/powershell-output-to-email-formatting-to-column/818076/6","author":{"@type":"Person","name":"jeffreycummings","url":"https://community.spiceworks.com/u/jeffreycummings"}},{"@type":"Answer","text":"
I tried to add the line break at the end, but got same horizontal row, not a column. I don’t want to post the entire PS script. I was hoping that what i provided someone could help me get it into a column, not a row.<\/p>\n
“EP1” = $AvailableUnitsE + “`n”<\/p>\n
“Au” = $AvailableUnitsP + “`n”<\/p>\n
“M” = $AvailableUnitsE2 + “`n”<\/p>\n
“M3” = $AvailableUnitsE3 + “`n”<\/p>\n
“Pe” = $AvailableUnitsPPE + “`n”<\/p>\n
“Pr” = $AvailableUnitsPr + “`n”<\/p>\n
“Vi” = $AvailableUnitsVi + “`n”<\/p>","upvoteCount":0,"datePublished":"2021-11-29T17:29:22.000Z","url":"https://community.spiceworks.com/t/powershell-output-to-email-formatting-to-column/818076/7","author":{"@type":"Person","name":"trublucali","url":"https://community.spiceworks.com/u/trublucali"}},{"@type":"Answer","text":"
If you are sending this as an HTML based body (rather than plain text) you need the HTML tag for new line.<\/p>\n
Try
in place of the “`n”<\/p>\n
Do remember that some mail clients cannot read HTML bodies, so an alternative plain text is still advisable. (Depending on your use case, of course)<\/p>","upvoteCount":0,"datePublished":"2021-11-29T18:01:53.000Z","url":"https://community.spiceworks.com/t/powershell-output-to-email-formatting-to-column/818076/8","author":{"@type":"Person","name":"philbristow7539","url":"https://community.spiceworks.com/u/philbristow7539"}},{"@type":"Answer","text":"
Alternatively, you could add the lot to an array and reference them from there rather than all separate variables. This could, I am reading between the lines here, allow you to add another value to each line to split out further if required later on for say, licenses by department / customer? Just a thought.<\/p>\n
$data = @(\n [pscustomobject]@{Field='EP1';Value=$AvailableUnitsE}\n [pscustomobject]@{Field='Au'; Value=$AvailableUnitsP}\n [pscustomobject]@{Field='M'; Value=$AvailableUnitsE2}\n [pscustomobject]@{Field='M3'; Value=$AvailableUnitsE3}\n [pscustomobject]@{Field='Pe'; Value=$AvailableUnitsPPE}\n)\n\nForeach($item in $data)\n{\n Write-Output ($item.Field + \" = \" + $item.Value)\n}\n<\/code><\/pre>\nGives you an output of<\/p>\n
EP1 = data
\nAu = data
\nM = data
\nM3 = data
\nPe = data<\/p>","upvoteCount":0,"datePublished":"2021-11-29T18:17:22.000Z","url":"https://community.spiceworks.com/t/powershell-output-to-email-formatting-to-column/818076/9","author":{"@type":"Person","name":"philbristow7539","url":"https://community.spiceworks.com/u/philbristow7539"}},{"@type":"Answer","text":"
Your problem is the output of ConvertTo-Html, it works in a very specific way to convert objects.<\/p>\n
What kind of object is $licensereport<\/em>? Without having the definition there is no way to look further for the error.<\/p>","upvoteCount":0,"datePublished":"2021-11-29T18:19:22.000Z","url":"https://community.spiceworks.com/t/powershell-output-to-email-formatting-to-column/818076/10","author":{"@type":"Person","name":"tulioarends","url":"https://community.spiceworks.com/u/tulioarends"}}]}}