Adding IP to multiple relay connectors

Adding IP to multiple relay connectors:

A customer has 5 Exchange 2013 servers. Each have an interal relay connector and an external relay connector.

Everytime e.g. a new scanner or a server needs to relay email, the IP has to be added to eigther the internal og external relay connectors.

Instead of adding the IP to five connectors each time, this script will do it for you.

It is very simple to expand this script with more choises and connectors.

Adding IP to multiple relay connectors

Adding IP to multiple relay connectors

I found the “Multiple Choise Menu” here on TechNet
I modified it so it could be used to adding IPs on the connectors.

Here is the script:

$newip = read-host 'Enter IP'
do {
write-host ""
write-host "1 - Relay_Internal"
write-host "2 - Relay_External"
write-host ""
write-host -nonewline "Choose your connector: "

$choice = read-host

write-host ""

$ok = $choice -match '^[12x]+$'

if ( -not $ok) { write-host "Invalid selection" }
} until ( $ok )

switch -Regex ( $choice ) {
$a = Get-ReceiveConnector exch01\relay_internal
$b = Get-ReceiveConnector exch02\relay_internal
$c = Get-ReceiveConnector exch03\relay_internal
$d = Get-ReceiveConnector exch04\relay_internal
$e = Get-ReceiveConnector exch05\relay_internal

$a = Get-ReceiveConnector exch01\relay_eksternal
$b = Get-ReceiveConnector exch02\relay_eksternal
$c = Get-ReceiveConnector exch03\relay_eksternal
$d = Get-ReceiveConnector exch04\relay_eksternal
$e = Get-ReceiveConnector exch05\relay_eksternal

$a.remoteipranges += $newip

Set-ReceiveConnector $a -RemoteIPRanges $a.remoteipranges
Set-ReceiveConnector $b -RemoteIPRanges $a.remoteipranges
Set-ReceiveConnector $c -RemoteIPRanges $a.remoteipranges
Set-ReceiveConnector $d -RemoteIPRanges $a.remoteipranges
Set-ReceiveConnector $e -RemoteIPRanges $a.remoteipranges

Thanks for reading

Leave a Reply

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