Report Help for Invoke-Command

I am running the below and it sends me an email that is table formated with columes Name and PSComputername. What I am trying to figure out is how can I make the table show red when the domain profile is not equal to DomainAuthenticated.

$time=[datetime]::Today.AddDays(-30) 
$Servers = Get-ADComputer -Filter {LastLogonDate -gt $time -And OperatingSystem -Like '*server*' } -SearchBase "OU=Domain,DC=com" 
$Results = ForEach ($Server IN $Servers){
Invoke-Command -computername $Server.Name -ScriptBlock {Get-NetConnectionProfile} | Select Name,PSComputername 
}
$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;}
TD {border-width: 1px;padding: 3px;border-style: solid;border-color: black;}
</style>
"@

$HTML = $Results | ConvertTo-Html -Head $Header -PreContent "<h3>Firewall Profile Status</h3>" -PostContent "<p><br/><h6>Run on: $(Get-Date)</p>" | Out-String
Send-MailMessage -From 'Status@domain.com' -To 'user@domain.com -Subject 'Firewall Profile Status' -SMTPServer "mail.domain.com" -Body $html -BodyAsHtml

freebird317,
Welcome to the forum.

Please when you post code, error messages, console output or sample data format it as code using the “preformatted text” button ( </> ).

Thanks in advance.

What you asked for is not achievable with a simple pure PowerShell way. But you’re not the first to ask for a reqwuirement like this. A great source of help is the ebook “Creating HTML Reports in PowerShell” by Don Jones. It is available cheap or free on leanpub.com

Basically you would need to add some CSS styles to your resulting HTML file header and insert some CSS/HTML tags to the proper places in your generated HTML output.

1 Like