Exchange 2010 Receive Connectors and Powershell

To dump them to a file:

$FormatEnumerationLimit =-1
Get-ReceiveConnector “” | fl remoteipranges > c:\scripts\iplist.txt

And to import them from a file:

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

This *will* append to any IP’s existing in the list already.

Finding all Exchange 2010 mailboxes that are not healthy and updating them

In an Exchange 2010 environment, for one reason or another some or many of your mailboxes may be left in an unhealthy state, and need to be reseeded. Rather than having to do each one manually, yo ucan use this PowerShell command:

Get-MailboxDatabaseCopyStatus -Server <servername> | where{$_.status -ne "Healthy"} | Update-MailboxDatabaseCopy -CatalogOnly

Note – this specific command will update the catalog only. If you require a full reseed, change as neccessary.

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 = @("","")
$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

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