Powershell script that allows you to get a list of all IP’s allowed to relay across all Relay Receive Connectors in your Exchange 2013 environment, and saves them to a text file for review. This is not a very elegant method, but it does the job for now.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
<# .Name Get-RelayIPUnique-Exchange2013.ps1 .Description Powershell script that allows you to get a list of all IP's allowed to relay across all Relay Receive Connectors in your Exchange environment. .Parameters None - execute directly from the Exchange Management Shell. .Version 0.2 .Author Kyle McDonald .Compatibility Exchange 2013 .Release Date May 2015 .Notes Change Log V0.1, 22/05/2015 - Initial version V0.2, 19/06/2015 - Added variables for Current_Date & Output_Filename #> # Define Variables $Script_Name = $MyInvocation.MyCommand.Name $Current_Date = get-date -format yyyyMMdd $Output_Filename = (Get-Childitem $Script_Name).basename + "-Log-" + $Current_Date + ".txt" # Get a list of all IP's from ReceiveConnectors with "Relay" in their name $FormatEnumerationLimit =-1 Get-ReceiveConnector | Where {$_.identity -like "*relay*"} | Select-Object -Property 'Identity','RemoteIPRanges' | FL > $Output_Filename # Remove lines starting with "Identity" (Get-content $Output_Filename) | select-string -pattern 'Identity' -notmatch | Out-File $Output_Filename # replace "RemoteIPRanges : {" with newline (Get-Content $Output_Filename) | Foreach-Object {$_ -replace "RemoteIPRanges : \{", "`n"} | Set-Content $Output_Filename # replace ", " with newline (Get-Content $Output_Filename) | Foreach-Object {$_ -replace ", ", "`n"} | Set-Content $Output_Filename # replace "}" with newline (Get-Content $Output_Filename) | Foreach-Object {$_ -replace "\}", "`n"} | Set-Content $Output_Filename # replace leading blank spaces on all lines (17 spaces) with newline (Get-Content $Output_Filename) | Foreach-Object {$_ -replace " ", "`n"} | Set-Content $Output_Filename # sort lines, case insensitive (Get-content $Output_Filename) | sort | get-unique > $Output_Filename # remove any blank lines (Get-content $Output_Filename) | ? {$_.trim() -ne "" } | set-content $Output_Filename # Done Write-Host "" Write-Host "Done! Opening file: $Output_Filename" -ForegroundColor Cyan Write-Host "" Invoke-Item $Output_Filename |