Link to home
Start Free TrialLog in
Avatar of Lennart Giaccotto
Lennart Giaccotto

asked on

Powershell output to email works, but readability is low

Hi there,

I've made a script which tells us which accounts will expire in the coming 2 weeks. This will be send through mail and will be scheduled. the mail part works, but the result is not easy to read. For this i wanted to make a html mail, maybe using a table (?) but i can't seem to get this working using my current script:

$myData = Search-ADAccount -AccountExpiring -TimeSpan "14" | Select-Object Name,AccountExpirationDate | Sort-Object AccountExpirationDate|convertto-csv -notypeinformation

Send-MailMessage -From xxx@xxx.nl -to xxx@xxx.nl -subject "Accounts about to expire" -SmtpServer xxx.xxx.local -body "$mydata"

Open in new window


Can someone point me in the right direction?
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Convert-HTML would be the solution.

$a = "<style>"
$a = $a + "BODY{background-color:peachpuff;}"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;}"
$a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;}"
$a = $a + "</style>"
$myData = Search-ADAccount -AccountExpiring -TimeSpan "14" | Select-Object Name,AccountExpirationDate | Sort-Object AccountExpirationDate|ConvertTo-HTML -head $a
Send-MailMessage -From xxx@xxx.nl -to xxx@xxx.nl -subject "Accounts about to expire" -SmtpServer xxx.xxx.local -body "$mydata"

Open in new window


https://technet.microsoft.com/en-us/library/ff730936.aspx
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Lennart Giaccotto
Lennart Giaccotto

ASKER

Thanks Guys, The small script did the job!
The other script adds some styling, but the -BodyAsHtml option is missing.