Search This Blog

Thursday, November 5, 2009

Powershell Script to add Ip addresses to receive connectors

Large organization have lots of application server which use SMTP to send all sorts of notifications. In Exchange Server 2007 you need to define an IP range or a list of IP addresses which you want to allow SMTP access to the Receive Connector. Large organizations have probably multiple hub transport servers and multiple connectors on these servers. If you need to modify these multiple receive connectors with a couple of honderd IP addresses, this script might become verry handy.

[code]

#Location where csv and script is located on the server.
$Path = '%Path%'
$file = read-host "Enter the name of the csv file"

#Hubtransportservers and the servers receiver connectors
$Node1 = '%Servername%\%ReceiveConnectors%'
$Node2 = '%Servername%\%ReceiveConnectors%'

#If you want to use a text file, you have to replace the csv by txt below.
$RCC = Get-receiveConnector $Node1
Import-csv "$Path\$file.csv" ForEach {$RCC.RemoteIpRanges += $_.IpAddresses}
$RCC Set-ReceiveConnector

$RCC = Get-receiveConnector $Node2
Import-csv "$Path\$file.csv" ForEach {$RCC.RemoteIpRanges += $_.IpAddresses}
$RCC Set-ReceiveConnector

Write-Host "IP Addresses have been added to receive connectors $Node1 and $Node2"
[/Code]

This script uses a CSV file, but you can alter it to a TXT file if you please.
You need to adjust following variables to make this script suitable for you:
  1. $Path = fill in the path where the csv or txt file can be located
  2. $NodeX = Fil in the paths of the recieve connectors on the multiple servers. This scripts references one receive connector on two different servers. You have have more servers/receive Connectors you need to define more node and more loops.

The scripts asks for the name of the csv file, so you are not bound to a physical file. Only the location of the file is hardcoded.

No comments:

Post a Comment