Quick Tip–adding multiple Remote IP Addresses to Receive Connectors…
A couple of weeks back an online buddy of mine contacted me to ask some advice. In essence his company was performing some major upgrades to their MPLS network which required some relatively significant changes to hosts that were allowed to relay off of the Exchange Server that was located on his site.
We had a discussion and agreed that they best way to do this was probably to add a new Receive Connector to his Exchange server dedicated to the MPLS and add the relevant Remote IP Ranges to his Receive Connector. Of course this is where it got a little complicated. Well I say complicated – more labour intensive.
You see, my buddies parent company who was managing the MPLS upgrade, had supplied him with a large Excel Spread sheet which contained all of the IP addresses of the hosts which needed to relay off this connector – about 180 entries in total.
Luckily for my buddy (Phil) the Exchange Management Shell was his friend – and by using a simple Text file – a few loops and the Set-ReceiveConnector cmdlet it was pretty easy to put together a Powershell script that would process all of the Remote IP Ranges for him.
Now, I should point out that there are a number of ways in PowerShell that this can be accomplished if you have a look around the Internet – but pretty much all of the examples (including mine) involve concatenating new Remote Remote IP ranges to the existing list on the receive connector and then committing them. My version of the script is designed to make the process of getting multiple IP values out of a text file and added to a specific Receive Connector more straight forward.
The following is a preview of the script – you can copy and paste it from below to a blank PS1 file on your Exchange Server – or download it from the download section of this post.
Exchange 2010 and Exchange 2013
Using the script
Download the script file which is relevant to your version of Exchange to one of your Exchange Servers.
In order to run the script you will need to ensure that your Powershell execution policies are set correctly. Review the following post that I prepared last year: http://www.telnetport25.com/2012/02/quick-tip-running-exchange-based-powershell-script-files-from-the-command-line-or-a-batch-file/ to check your settings.
Before you use the script you should ensure that you have all of the IP addresses that you wish to add to a particular Receive Connector stored within a text file.
Each host should appear on a separate line. You can also use the CDIR address notation for an entire subnet if you wish to allow all hosts in a range to relay (for example add a line for 172.31.253.0/24) .
An example file is shown below:
Open the Exchange Management Shell, navigate to the directory where you have downloaded the script file and type:
You will then be presented with a list of all the detected receive connectors that the script has located. Choose the connector via its numerical identifier (the numbers on the left hand side).
You will then be prompted to locate your IP Range text file – browse to it and then click on the “Open” button.
The script will then process each host entry and add it to the selected Receive Connector.
After the script has completed – if you check the [ Network –> Receive Mail from remote servers that these IP addresses ] in the Exchange Management Console, you should see that your addresses have been added.
I hope that you find this post and script useful, and that it might help automate this process for someone else in the future.