Get remote server names from receive connector


I was asked to make a list of all remote servers (including IP addresses) which are able to use a receive connector in Exchange 2010.

2013-08-21 00_59_27

The remote IP addreses of the receive connector can be found under RemoteIPRanges property of Get-ReceiveConnector cmdlet. Those addreses can be devided based on RangeFormat declaration:

  • SingleAddress (10.10.10.5)
  • CIDR (10.10.10.5/24)
  • LoHi (10.10.10.5-10.10.10.10)

Theoretically if we need to get all IP addresses, we have to know also IP addresses in particular ranges and then we can resolve those addreses in DNS.

Here are two functions. The first one (New-IPRange) is created by Dr.Tobias Weltner and ensures us to find all IP addresses (also from CIDR or LoHi ranges). The second one is my helper (Get-ReceiveConnectorRemoteIPName) which goes through RemoteIPRanges, calls the first function and resolves IP address by System.Net.Dns .NET class. The processing time depends on amount of IP addreses so be careful about your ranges!

function New-IPRange ($start, $end) {
 # created by Dr. Tobias Weltner, MVP PowerShell
 $ip1 = ([System.Net.IPAddress]$start).GetAddressBytes()
 [Array]::Reverse($ip1)
 $ip1 = ([System.Net.IPAddress]($ip1 -join '.')).Address
 $ip2 = ([System.Net.IPAddress]$end).GetAddressBytes()
 [Array]::Reverse($ip2)
 $ip2 = ([System.Net.IPAddress]($ip2 -join '.')).Address
 for ($x=$ip1; $x -le $ip2; $x++) {
 $ip = ([System.Net.IPAddress]$x).GetAddressBytes()
 [Array]::Reverse($ip)
 $ip -join '.'
 }
}

function Get-ReceiveConnectorRemoteIPName ($Identity) {
 $Connector = Get-ReceiveConnector -identity $Identity | select Identity,RemoteIPRanges
 if($Connector -ne $null){
 $IPs = $Connector.RemoteIPRanges | % { New-IPRange $_.LowerBound $_.UpperBound }
 foreach($IP in $IPs){
 $Output = New-Object PSObject
 $IPName = ([Net.DNS]::GetHostEntry("$ip")).HostName
 if($IPName -eq $IP){$IPName="unresolvable"}
 $output | add-member -Type NoteProperty -name “ReceiveConnector” -value $Connector.Identity
 $output | add-member -Type NoteProperty -name “RemoteIp” -value $IP
 $output | add-member -Type NoteProperty -name “RemoteName” -value $IPName
 $output
 }
 }
}

How to use it? Only paste both functions into EMS, that’s it.

2013-08-21 00_44_51

Now you are ready to use both functions especially Get-ReceiveConnectorRemoteIPName:

[PS] C:\>Get-ReceiveConnectorRemoteIPName "EX2010S01\Application Relay"

ReceiveConnector             RemoteIp    RemoteName
----------------             --------    ----------
EX2010S01\Application Relay  10.10.1.16  appolo.ficility.intra
EX2010S01\Application Relay  10.10.2.2   helt01.ficility.intra
EX2010S01\Application Relay  10.10.2.3   unresolvable
EX2010S01\Application Relay  10.10.2.4   unresolvable
EX2010S01\Application Relay  10.10.1.25  kepro.ficility.intra

2013-08-21 01_54_48

Feel free to use Get-ReceiveConnectorRemoteIPName cmdlet in the following scenarios:

[PS] C:\> Get-ReceiveConnectorRemoteIPName "EX2010S01\Application Relay"| Export-Csv -Path "C:\ReceiveConnectorRemoteIPName.csv"

[PS] C:\> $connectors = Get-ReceiveConnector | ? { $_.identity -like "*relay*" }
[PS] C:\> $connectors| % { Get-ReceiveConnectorRemoteIPName $_.identity }
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s