Copy Exchange Receive Connector Settings using PowerShell

Currently working on rebuilding a failed Exchange 2016 DAG node, installing Exchange, and getting the databases in sync again… And then you remember that the Anonymous Relay settings are something that’s configured on each node separately and it contains a lot of IP-addresses πŸ™ This blog post shows you a way to copy an existing Receive Connector to a new Exchange server easily!

What is DAG?

A database availability group (DAG) is the base component of the Mailbox server’s high availability and site resilience framework built into the Microsoft Exchange Server. A DAG is a group of up to 16 Mailbox servers that hosts a set of databases and provides automatic database-level recovery from failures that affect individual servers or databases.

Requirements of the script

Well… It should copy the settings of the connector to another server and preserve:

  • The Remote IP Addresses listed on the Scoping tab
  • The Binding on the server (Port 25)
  • Security Settings (TLS/Anonymous)
  • Message size limit
  • The hop count

Running the script

Instead of just filling in some variables, I wanted to select a source and destination. Out-Gridview helps in that, when you run the script it will look like this: (I Did some blurring of course πŸ˜‰ )

  • Select the Receive Connector
  • Select the destination server on which the Receive Connector should be created
  • If all goes well, you should see created Receive Connector in the console output
  • And in the Exchange Admin Center

The Script

Below is the script, the Whatif parameter is set to $True so you can see what it would do, set to $False to go ahead and create the Receive Connector

#Add Microsoft Exchange snapins
Add-PSSnapin Microsoft.Exchange*

#Set variables
$receiveconnector = Get-receiveconnector | Out-GridView -OutputMode Single -Title 'Please select the Receive Connector to copy the settings from and click OK'
$newserver = Get-ExchangeServer | Out-GridView -OutputMode Single -Title 'Please select destination server to create the Receive Connector on and click OK'

#Set the options for creating the Receive Connector
$options = @{
    Bindings             = $receiveconnector.Bindings
    Enabled              = $receiveconnector.Enabled
    MaxHopCount          = $receiveconnector.MaxHopCount
    MaxLocalHopCount     = $receiveconnector.MaxLocalHopCount
    MaxMessageSize       = $receiveconnector.MaxMessageSize
    MessageRateLimit     = $receiveconnector.MessageRateLimit
    Name                 = $receiveconnector.Identity.Name
    PermissionGroups     = $receiveconnector.PermissionGroups.ToString().Split(',')[0]
    ProtocolLoggingLevel = $receiveconnector.ProtocolLoggingLevel
    RemoteIPRanges       = $receiveconnector.RemoteIPRanges
    Server               = $newserver
    SizeEnabled          = $receiveconnector.SizeEnabled
    TransportRole        = $receiveconnector.TransportRole
    Usage                = 'Custom'
    WhatIf               = $True
    
}

#Create new Receive Connector and copy the settings from the existing one
New-ReceiveConnector @options

External relay

Copying the connector will copy all the settings except the one if the connector can be used for external addresses if that is needed… Then run the PowerShell line below for that in an Exchange Management Shell: (Replace servername for your server name of course πŸ˜‰ )

Get-Receiveconnector 'servername\allow anonymous relay' |  Add-ADPermission -User "NT AUTHORITY\ANONYMOUS LOGON" -ExtendedRights "Ms-Exch-SMTP-Accept-Any-Recipient"

Download the script(s) from GitHub here

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.