Exchange 2010 transport log report using CSV


$date = Get-Date
$today = $date.ToShortDateString()
$lastweek = $date.AddDays(-7).ToShortDateString()
$result = Get-MessageTrackingLog -recipients <enter email address here> -start $lastweek -end $today | Select-Object Timestamp,Sender,MessageSubject
$csvresult = $result | Export-Csv c:\scripts\solution_center_emails.csv

# Configuration
$emailFrom = "<enter from address here>"
$emailTo = @("address1@domain.com","address2@domain.com")
$emailSubject = "<enter subject here>"
$emailBody = "See the attached file in CSV format for the calls from $lastweek to $today"
$emailAttachment = "c:\scripts\solution_center_emails.csv"
$smtpServer = "<enter SMTP server here>"

# Send E-Mail
Send-MailMessage -To $emailTo -From $emailFrom -Subject $emailSubject -Body $emailBody -Attachment $emailAttachment -SmtpServer $smtpServer

#Clean up / Remove File
if (Test-Path $emailAttachment) {Remove-Item $emailAttachment}

Exchange 2010 transport log report using HTML


$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;padding: 0px;border-style: solid;border-color: black;background-color:white}"
$a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:white}"
$a = $a + "</style>"

$date = Get-Date
$today = $date.ToShortDateString()
$yesterday = $date.AddDays(-1).ToShortDateString()

$result = Get-MessageTrackingLog -recipients <enter email address here> -start $yesterday -end $today | Select-Object MessageSubject,Sender,Timestamp
$htmlresult = $result | ConvertTo-HTML -head $a -body "<H4>Emails addressesd to <enter email address here> from $yesterday to $today</H4>"

# Configuration
$emailFrom = "<enter from address here>"
$emailTo = "<enter to address here>"
$emailSubject = "<enter Subject here>"
$emailMessage = $htmlresult
$smtpServer = "<enter SMTP server here>"

# SMTP Object
$smtp = New-Object System.Net.Mail.SmtpClient($smtpServer)

# Send E-Mail
$msg = New-Object System.Net.Mail.MailMessage $emailFrom, $emailTo, $emailSubject, $emailMessage
$msg.isBodyhtml = $true
$smtp.send($msg)

Adding receive connector IP addresses using PowerShell

Be sure to modify your values for the connector name, and file path. This will append to the existing path, not over write it. It will throw an error and continue if a value already exists.

$rc = Get-ReceiveConnector -Identity “Anonymous SMTP Relay Connector”
Get-Content "c:\scripts\addrelayips.txt" | foreach {$rc.RemoteIPRanges += "$_"}
Set-ReceiveConnector "Anonymous SMTP Relay Connector" -RemoteIPRanges $rc.RemoteIPRanges