Automation

 View Only
  • 1.  Color a single text of one mail

    Posted May 18, 2017 11:56 AM

    hi, we are trying to color the text ( "ALERT") with the color red.
    But we can not find a solution.

    Do you know which property to use to color the text?
    In the post there is also the result that produces this script .. as you can see from the image I would color the text of the last column.
    Thanks so much

    $start=get-date

    $Pools=get-pool|select Pool_ID,Enabled,RefreshPolicy,Minimumcount,MaximumCount,VMcreated,Perc,Nota

    $a=0

    $soglia=90

    foreach ($Pool in $Pools)

    {

    $Pools[$a].VMcreated=(Get-DesktopVM -pool_id $Pools[$a].pool_id).Count

    $Pools[$a].Perc=[int]($Pools[$a].VMcreated*100/$Pools[$a].maximumcount)

    #$allerta=$Pools[$a].MaximumCount-$soglia

    if ($Pools[$a].perc -ge $soglia)

        {

         $Pools[$a].Nota=("ALERT")

        }

    $a=$a+1

    }

    $end=get-date

    $Style = "

    <style>

        BODY{background-color:white;}

        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:#778899}

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

        tr:nth-child(odd) { background-color:#d3d3d3;}

        tr:nth-child(even) { background-color:white;}   

    </style>

    "

    $EmailFrom = "Report Pools <no-replay@xxxxxx.xx>"

    # $EmailTo =

    $EmailSubject = "Testo"   

    $SMTPServer = "smtp"

    $emailBody1=$Pools|ConvertTo-HTML -Head $style|out-string

    function send_email {

    $mailmessage = New-Object system.net.mail.mailmessage

    $mailmessage.from = ($emailfrom)

    $mailmessage.To.add($emailto)

    $mailmessage.Subject = $emailsubject

    $mailmessage.Body = $emailbody

    $attachment = New-Object System.Net.Mail.Attachment($emailattachment, 'text/plain')

    $mailmessage.IsBodyHTML = $true

    $SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 25) 

    $SMTPClient.Credentials = New-Object System.Net.NetworkCredential("$SMTPAuthUsername", "$SMTPAuthPassword")

    $SMTPClient.Send($mailmessage)

    }

    send_email



  • 2.  RE: Color a single text of one mail
    Best Answer

    Posted May 19, 2017 08:59 AM

    You can color the text ( "ALERT") with the color red by modifying line 31 of your script into:

    $emailBody1=($Pools|ConvertTo-HTML -Head $style|out-string).Replace('<td>ALLERT</td>','<td style="color:red">ALLERT</td>')