Quantcast
Channel: Exchange Server 2013 - General Discussion forum
Viewing all articles
Browse latest Browse all 4521

Format Cells or Font Based on Value HTML Powershell

$
0
0

Hello Everyone, 

i do have an script i've been making to get report of server certificates for now i do have the part to get certs, convert to html, send it by email but i cant format the cells or the font, so when i get a certified about expire (10 days) get colored on red 11 to 20 days get yellow and greater than 20 days appear on green.

could you help with this.

Thanks in advance.

Script---------

$Servers = “Server1”,”Server2","Server3"

$a = "<style>"
$a = $a + "BODY{background-color:White;}"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;text-align:center;padding: 0px;border-style: solid;border-color: black;background-color:lightslategray}"
$a = $a + "TD{border-width: 1px;text-align:center;padding: 0px;border-style: solid;border-color: black;background-color:gainsboro}"
$a = $a + "</style>"


Invoke-Command -ComputerName $Servers -ScriptBlock {get-childitem cert:LocalMachine\My -recurse | where-object {($_.NotAfter -gt (get-date) -or ($_.NotAfter -lt (get-date)))} |
select-Object FriendlyName,Subject,@{Name="Days Until Expires";Expression={($_.NotAfter).subtract([DateTime]::Now).days}},Thumbprint | where "Days Until Expires" -lt 365 |
Sort "Days Until Expires" } | ConvertTo-HTML -head $a -Body "<H2>Certificates about to expire</H2>"| Out-File C:\CTest.html

$body = Get-Content ("C:\CTest.html")

function sendmail([string] $body) 

$SmtpClient = new-object system.net.mail.smtpClient 
$MailMessage = New-Object system.net.mail.mailmessage
$SmtpClient.Host = "10.1.1.27"
$mailmessage.from = "irving@contoso.com" 
$mailmessage.To.add("irving@contoso.com")
$mailmessage.Subject = "Test report Certs" 
$mailmessage.Body = $body 
$MailMessage.IsBodyHtml = $TRUE 
$smtpclient.Send($mailmessage)

sendmail $body 


Viewing all articles
Browse latest Browse all 4521

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>