Hi folks,
I would love to share with you code for adding and removing IP address to receive connectors. In the receive connector there is an attribute called RemoteIPRanges. It is a multi-value attribute that contains list of hosts that can send emails to to an Exchange server.
Let's imagine that we need to add IP address of 192.168.164.39 to the remote IP ranges by running below command all the IP addresses in white list will be overwritten by this only IP address and mail flow will be broken.
Set-ReceiveConnector "EXCH01\Internet Mail" -RemoteIPRanges 192.168.164.39
To do it from PowerShell we can use the code as below:
$Server = $(Get-WmiObject Win32_Computersystem).name
$RecvConn = Get-ReceiveConnector "$Server\Internet Mail"
$RecvConn.RemoteIPRanges += "192.168.164.39"
Set-ReceiveConnector $RecvConn -RemoteIPRanges $RecvConn.RemoteIPRanges
When you want to remove a single IP address you will need to replace in the code $RecvConn.RemoteIPRanges += with $RecvConn.RemoteIPRanges -=. As you can easily guess plus is used for addition while minus for removal. Thefore the code for removing the IP address of 192.168.35.169 from receive connector will be something like this one:
$Server = $(Get-WmiObject Win32_Computersystem).name
$RecvConn = Get-ReceiveConnector "$Server\Internet Mail"
$RecvConn.RemoteIPRanges -= "192.168.35.169"
Set-ReceiveConnector $RecvConn -RemoteIPRanges $RecvConn.RemoteIPRanges
After either removal or adding IP address to IP address ranges don't forget to check if your receive connector has been successfully updated. For this purpose you can run the following command (provided that you run one of the previous codes you can use $RecvConn variable do identify your connector):
Get-ReceiveConnector $RecvConn |select -ExpandProperty RemoteIpRanges |select Expression |sort Expression
In the returned list you should see new IP address if you added it or the removed IP address should disappear
Enjoy!
No comments:
Post a Comment