Adding IPs to RemoteIPRanges using a script
I have a small script where I read a list of IP address from text file and I want to add the IP address to the RemoteIPRanges of a Receive Connector I have set up. The script:
$hubRe = Get-ReceiveConnector EX-HUB-RE\AppRelay--EX-HUB-RE$listIP = Get-Content .\ipList2.txtforeach($ipAdd in $listIP){ $toAdd = '"' $toAdd += $ipAdd $toAdd += '"'
$hubRe.RemoteIPRanges += $toAdd $hubRe | Set-ReceiveConnector
$toAdd = ""}
When I run the script, I get the following errors:
Exception setting "RemoteIPRanges": "Cannot convert value "System.Object[]" totype "Microsoft.Exchange.Data.MultiValuedProperty`1[Microsoft.Exchange.Data.IPRange]". Error: "Failed to convert "10.99.9.99" from System.String to Microsoft.Exchange.Data.IPRange.""At C:\Documents and Settings\martin_s\Desktop\setAPCrelay.ps1:14 char:11+ $hubRe.R <<<< emoteIPRanges += $toAdd
Questions:
How can I add the IP addresses from my text file to the RemoteIPRanges of a connector?
OR
How can I convert a string to microsoft.exchange.data.iprange?
October 20th, 2008 9:55pm
1. You don't have to use $toAdd = '"' because what we define in-between " is value and we can directly pass if we are passing through a variable.
2. You need to get the Receive Connector configuration everytime inside the loop.
3. Your IP range should be in 192.168.1.2-192.168.1.10 format and each line one range should be placed in iplist2.txt file.
$listIP = Get-Content .\ipList2.txtforeach($ipAdd in $listIP){
$hubRe = Get-ReceiveConnector EX-HUB-RE\AppRelay--EX-HUB-RE$hubRe.RemoteIPRanges += $ipAdd$hubRe | Set-ReceiveConnector
}
References:
Modifying Multivalued Properties
http://technet.microsoft.com/en-us/library/bb684908(EXCHG.80).aspx
Set-ReceiveConnector
http://technet.microsoft.com/en-us/library/bb125140(EXCHG.80).aspx
Free Windows Admin Tool Kit Click here and download it now
October 21st, 2008 5:29am
You can refer to http://www.eggheadcafe.com/software/aspnet/31433281/exchange-2007-ps-command.aspx
Excerpt from that thread:
$hubRe = Get-ReceiveConnector "RelayConnector"
import-csv "c:\ipList2.txt" | foreach {$hubRe.RemoteIPRanges +=
$_.IPAddresses}
$hubRe| Set-ReceiveConnector
Hope it helps.
Xiu
October 22nd, 2008 10:19am
Thanks Xiu. That did the trick.
Free Windows Admin Tool Kit Click here and download it now
October 22nd, 2008 6:15pm