Introduction to Send Connectors in Exchange

In Microsoft Exchange 2016 and 2019, send connectors are critical in managing email flow from Exchange servers to external domains. These connectors are essential for delivering outbound emails, ensuring that messages are routed effectively to their intended recipients across the internet or other mail systems. Administrators configure send connectors to control various aspects of mail flow, such as the source servers, address space, and network settings, allowing organizations to implement specific transportation rules for email distribution.

Updating Send Connectors Using PowerShell Commands

If you are adding additional Exchange Servers to your environment, whether it is for coexistence or just to handle more mailboxes, manually updating 50 or several hundred can take some time and allows room for error.

I put together a PowerShell script that adds in the new servers you specify but does not remove any. Usually, when you try to add servers without telling PowerShell to leave what is current, it just overrides the source servers.

The script produces an output to show what changes have been made to each Send Connector. You may have a Send Connector that has 2x new Exchange Servers but is missing 3x and it will only add the 3x that is missing, however, you may have another Send Connector that does not have the 5x new servers in, and the output will show you that all 5x have been added.

You need to update two sections in the script below, which are as follows:

  • $filePath – This is where you saved the text file that you will use to list all the Send Connectors. You only need the name of the Send Connector, one on each line. No headings required.
  • $serversToAdd – I manually specify the servers as you can see below, however you can change it to use a text file as well if you have many to add.
  • I added the SnapIn for Exchange 2016/2019 as if you run this from PowerShell ISE, it will fail on the Get-SendConnector command, however, if you run it from the Exchange Management Shell, no SnapIn is required.
#Load the Exchange 2016/2019 SnapIn
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn
# Path to the text file
$filePath = "C:\path\to\send_connectors.txt"
# Define the servers to add
$serversToAdd = @("Server1", "Server2", "Server3")
# Convert all server names to uppercase
$serversToAdd = $serversToAdd | ForEach-Object { $_.ToUpper() }
# Read the file line by line
$sendConnectors = Get-Content -Path $filePath
foreach ($sendConnectorName in $sendConnectors) {
    # Get the existing send connector
    $sendConnector = Get-SendConnector -Identity $sendConnectorName
    # Get the current list of source transport servers and convert to uppercase strings
    $currentServers = $sendConnector.SourceTransportServers | ForEach-Object { $_.ToString().ToUpper() }
    # Find the servers that are not already in the current list
    $serversToActuallyAdd = $serversToAdd | Where-Object { $_ -notin $currentServers }
    if ($serversToActuallyAdd.Count -gt 0) {
        # Combine the existing servers with the new ones
        $updatedServers = $currentServers + $serversToActuallyAdd
        # Update the send connector with the combined server list
        Set-SendConnector -Identity $sendConnectorName -SourceTransportServers $updatedServers
        Write-Output "Updated $sendConnectorName with new servers: $serversToActuallyAdd"
    } else {
        Write-Output "No new servers to add for $sendConnectorName"
    }
}
Write-Output "Send connectors updated successfully."

Depending on the number of servers to add to each Send Connector, the script will take a few minutes to complete.

Please remember that the change is not instant; Active Directory has to update, and you should see Transport Events in the Application Event Log when the changes take place. If you have a large environment where replication has to take place amongst a large number of domain controllers, this could take longer than 15 minutes.

Hope it helps.

Discover more from Everything-PowerShell

Subscribe now to keep reading and get access to the full archive.

Continue reading