ndalmolin_13
asked on
Help with HTML email report generated from a Powershell script
Greetings Powershell Experts,
I have written a small Powershell script (with the help of various Experts here on Experts-Exchange) that basically allows me to input a department in our organization and generate a list of the users in that department along with their mailbox size. I have decided to try and make the output an HTML report that can be emailed to myself or someone else. The code for the script is as follows:
$Header = "<style type='text/css'>`n" + `
"td { width: 200px }`n" + `
"th { text-align: left }`n" + `
"</style>"
$Department = Read-Host "Input the department for which you would like to run the pre-migration mailbox report."
$Users = Get-user -Filter {Department -like $Department}
$title = foreach ($user in $Users) {select-object title}
$Body = foreach ($user in $Users) {
Get-MailboxStatistics $User.samaccountname | `
Select-object `
@{n="User";e={$_.DisplayNa me}}, `
@{n="Job Title";e={$user.title}}, `
@{n="Mailbox Size (MB)";e={$_.totalitemsize. value.ToMB ()}}}
ConvertTo-HTML -Title "Pre-migration Mailbox Report" -Head $Header
$Mail = New-Object System.Net.Mail.MailMessag e( `
"MailAdmin@domain.com", `
"nick@domain.com", `
"PRE-MIGRATION REPORT", `
$Body)
$Mail.IsBodyHTML = $True
$Smtp = New-Object System.Net.Mail.SmtpClient ("cas-hub0 1.summitla n.states")
$Smtp.Send($Mail)
PLEASE NOTE: I DON’T UNDERSTAND THE HTML STUFF AT ALL. I FOUND A COUPLE EXAMPLES AND PATCHED THIS TOGETHER TO SEE IF I COULD GET IT TO WORK.
When I run this, I get a blank email. Can someone help me with the HTML part of this?
Thanks,
Nick
I have written a small Powershell script (with the help of various Experts here on Experts-Exchange) that basically allows me to input a department in our organization and generate a list of the users in that department along with their mailbox size. I have decided to try and make the output an HTML report that can be emailed to myself or someone else. The code for the script is as follows:
$Header = "<style type='text/css'>`n" + `
"td { width: 200px }`n" + `
"th { text-align: left }`n" + `
"</style>"
$Department = Read-Host "Input the department for which you would like to run the pre-migration mailbox report."
$Users = Get-user -Filter {Department -like $Department}
$title = foreach ($user in $Users) {select-object title}
$Body = foreach ($user in $Users) {
Get-MailboxStatistics $User.samaccountname | `
Select-object `
@{n="User";e={$_.DisplayNa
@{n="Job Title";e={$user.title}}, `
@{n="Mailbox Size (MB)";e={$_.totalitemsize.
ConvertTo-HTML -Title "Pre-migration Mailbox Report" -Head $Header
$Mail = New-Object System.Net.Mail.MailMessag
"MailAdmin@domain.com", `
"nick@domain.com", `
"PRE-MIGRATION REPORT", `
$Body)
$Mail.IsBodyHTML = $True
$Smtp = New-Object System.Net.Mail.SmtpClient
$Smtp.Send($Mail)
PLEASE NOTE: I DON’T UNDERSTAND THE HTML STUFF AT ALL. I FOUND A COUPLE EXAMPLES AND PATCHED THIS TOGETHER TO SEE IF I COULD GET IT TO WORK.
When I run this, I get a blank email. Can someone help me with the HTML part of this?
Thanks,
Nick
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thanks for the points,
D
D
It doesn't create a HTML email as I've had loads of security warnings from various email clients in the past. instead, it attaches a HTML file.
Open in new window