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.

"EP1" = $AvailableUnitsE

    "Au" = $AvailableUnitsP

    "M" = $AvailableUnitsE2

    "M3" = $AvailableUnitsE3   

    "Pe"    = $AvailableUnitsPPE

    "Pr" = $AvailableUnitsPr   

    "Vi" = $AvailableUnitsVi

   

    

    }

 

    $Header = @"

    <style>

    TABLE {border-width: 1px; border-style: solid; border-color: black; border-collapse:

    collapse;}

    TH {border-width: 1px; padding: 3px; border-style: solid; border-color: black;

    background-color: #6495ED;}

    TD {border-width: 1px; padding: 3px; border-style: solid; border-color: black;}

    </style>

 

    "@

 

    $body = $licenseReport | ConvertTo-Html -head $Header | out-string

 

 

 

    $messagereport = @{

    subject =  "License Counts"

    Body =  $body

    From = licensing@xx.com

    To = james.s@xx.com

    SmtpServer = “10.1.1.1”}

    Send-MailMessage @messagereport -BodyAsHtml
5 Spice ups

I think you messed up the formatting of the script. The start is NOT Powershell syntax??

Also

 SmtpServer = “10.1.1.1”}

will fail. Try:

 SmtpServer = "10.1.1.1"}

The PS script currently works fine. I just need to have it format into a column, not a row.

The script you posted is missing stuff at the beginning.

¿Where is $licensereport defined?

It sounds like you want to manually include the line breaks, or the carriage returns.

This would simply be “text for entire line” + $maybe variable +

n (backtick with letter n) is the line break I believe, so you can put it at the end of each line + "n"

like that…!

Hope that helps,

Jeff Cummings

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.

“EP1” = $AvailableUnitsE + “`n”

“Au” = $AvailableUnitsP + “`n”

“M” = $AvailableUnitsE2 + “`n”

“M3” = $AvailableUnitsE3 + “`n”

“Pe” = $AvailableUnitsPPE + “`n”

“Pr” = $AvailableUnitsPr + “`n”

“Vi” = $AvailableUnitsVi + “`n”

If you are sending this as an HTML based body (rather than plain text) you need the HTML tag for new line.

Try
in place of the “`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)

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.

$data = @(
    [pscustomobject]@{Field='EP1';Value=$AvailableUnitsE}
    [pscustomobject]@{Field='Au'; Value=$AvailableUnitsP}
    [pscustomobject]@{Field='M'; Value=$AvailableUnitsE2}
    [pscustomobject]@{Field='M3'; Value=$AvailableUnitsE3}
    [pscustomobject]@{Field='Pe'; Value=$AvailableUnitsPPE}
)

Foreach($item in $data)
{
    Write-Output ($item.Field + " = " + $item.Value)
}

Gives you an output of

EP1 = data
Au = data
M = data
M3 = data
Pe = data

Your problem is the output of ConvertTo-Html, it works in a very specific way to convert objects.

What kind of object is $licensereport? Without having the definition there is no way to look further for the error.