Import IPs Receive Connector

Recently I had to Import IPs Receive Connector into Exchange 2019 server. However, this was for in excess of 300 IP addresses for a regional EMEA Exchange server. Now I was lucky enough to have a central list of IP addresses that had all the SMTP Relay traffic already.

So I created my PowerShell script to read from this. I also added output and logic so if the IP was already in the list it would note this. Meaning that the same CSV can be imported time after time on amendments to make housekeeping easier for junior members of staff. I have also even built this out as a scheduled tasks to help smaller organization keep up to date where many IT users may have access to the CSV file in a shared location, and having the script run hourly to save tickets being logged and additional work required. As with all automation the sky is the limit. Amend this to however, the organization you work at requires to save admin effort.

Import IPs Receive Connector

How To: Import IPs Receive Connector

Firstly, ensure you have a list of IP addresses saved in a CSV file or equivalent. In this demo this looked like below.


Secondly ensure you are running the following in Exchange PowerShell. If you prefer to use PowerShell ISE then import the module via our guide here.

As a final step, please run the following PowerShell script.

$ImportFile ="C:\Temp\ImportIPsReceiveConnector.csv"
$Connector ="EXCHANGE01\Default Frontend EXCHANGE01"
$logFile  = ("C:\Temp\" + "\ImportIPsReceiveConnector" + ".log")
$Timestamp = Get-Date -Format "yyyyMMddHHmmss"

#@#Import IP addresses from CSV This looks for the Header "IPAddress" in the CSV
$IPAddresses = Import-Csv $ImportFile

#@# Get receive connector
$RecieveConnector = Get-ReceiveConnector $Connector

#@# Get receive connector remote IP addresses
$RemoteIPRanges = $RecieveConnector.RemoteIPRanges

#@# Loop through each IP address from the CSV
foreach ($IP in $IPAddresses.IPAddress) {

#@# Check if IP address is already in the connector
    if ($RemoteIPRanges -contains $IP)
        Write-Host "IP address $($IP) already exist in receive connector $($RecieveConnector)" -ForegroundColor Red
        $LogMsg = "$($Timestamp),Failure,IP address $($IP) already exist in receive connector $($RecieveConnector)"
        $LogMSg | Out-File $logFile -Append
    #@# If IP address is not already added the IP will now be added
    else {
        $RemoteIPRanges += $IP

        #@# Add the IP Address into the Connector
        Set-ReceiveConnector $RecieveConnector -RemoteIPRanges $RemoteIPRanges 
        Write-Host "IP address $($IP) added in to receive connector $($RecieveConnector)" -ForegroundColor Green
        $LogMsg = "$($Timestamp),Success,IP address $($IP) added into receive connector $($RecieveConnector)"
        $LogMSg | Out-File $logFile -Append

Please not the script above comes with no warranty and we accept not responsibilities for the actions taken during running this script.

Finally, Once completed you can review the logfile added if you would like to have this running as a scheduled task or bulk importing a large number.

Also, subsequent runs would enter the log file as below.

Additional Details: Exchange

If you want to find more details please visit the attached tech net article from Microsoft for more details.

Also, if you want to find more details out on how Exchange please check out my other blog posts. Furthermore being from a consultant in this area. Shortly, I am hoping to have numerous blog posts. These will be on the Exchange online PowerShell topics over the coming weeks on the site.

Finally please feel free to drop a comment below or share this blog post if it has helped you.

Please Leave a Comment

If the above has helped you in increase the efficiency of bulk importing IP addresses into a receive connector then please let us know by leaving a comment or feel free to share the article below. If you have any errors or require more details on anything covered then please comment.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *