{"id":77,"date":"2014-05-22T16:36:20","date_gmt":"2014-05-22T08:36:20","guid":{"rendered":"http:\/\/kylemcdonald.com.au\/?p=77"},"modified":"2018-08-14T00:37:25","modified_gmt":"2018-08-13T16:37:25","slug":"powershell-script-to-get-a-unique-list-of-ips-added-to-exchange-2013-receive-connectors-2","status":"publish","type":"post","link":"https:\/\/kylemcdonald.com.au\/2014\/05\/22\/powershell-script-to-get-a-unique-list-of-ips-added-to-exchange-2013-receive-connectors-2\/","title":{"rendered":"Powershell script to get a unique list of IP’s added to Exchange 2013 Receive Connectors"},"content":{"rendered":"
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.<\/p>\n
<\/p>\n
<#\r\n.Name\r\n Get-RelayIPUnique-Exchange2013.ps1\r\n.Description\r\n 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.\r\n.Parameters\r\n None - execute directly from the Exchange Management Shell.\r\n.Version\r\n 0.2\r\n.Author\r\n Kyle McDonald\r\n.Compatibility\r\n Exchange 2013\r\n.Release Date\r\n May 2015\r\n.Notes\r\nChange Log\r\nV0.1, 22\/05\/2015 - Initial version\r\nV0.2, 19\/06\/2015 - Added variables for Current_Date & Output_Filename\r\n#>\r\n \r\n# Define Variables\r\n$Script_Name = $MyInvocation.MyCommand.Name\r\n$Current_Date = get-date -format yyyyMMdd\r\n$Output_Filename = (Get-Childitem $Script_Name).basename + \"-Log-\" + $Current_Date + \".txt\"\r\n \r\n# Get a list of all IP's from ReceiveConnectors with \"Relay\" in their name\r\n$FormatEnumerationLimit =-1\r\nGet-ReceiveConnector | Where {$_.identity -like \"*relay*\"} | Select-Object -Property 'Identity','RemoteIPRanges' | FL > $Output_Filename\r\n \r\n# Remove lines starting with \"Identity\"\r\n(Get-content $Output_Filename) | select-string -pattern 'Identity' -notmatch | Out-File $Output_Filename\r\n \r\n# replace \"RemoteIPRanges : {\" with newline\r\n(Get-Content $Output_Filename) | Foreach-Object {$_ -replace \"RemoteIPRanges : \\{\", \"`n\"} | Set-Content $Output_Filename\r\n \r\n# replace \", \" with newline\r\n(Get-Content $Output_Filename) | Foreach-Object {$_ -replace \", \", \"`n\"} | Set-Content $Output_Filename\r\n \r\n# replace \"}\" with newline\r\n(Get-Content $Output_Filename) | Foreach-Object {$_ -replace \"\\}\", \"`n\"} | Set-Content $Output_Filename\r\n \r\n# replace leading blank spaces on all lines (17 spaces) with newline\r\n(Get-Content $Output_Filename) | Foreach-Object {$_ -replace \" \", \"`n\"} | Set-Content $Output_Filename\r\n \r\n# sort lines, case insensitive\r\n(Get-content $Output_Filename) | sort | get-unique > $Output_Filename\r\n \r\n# remove any blank lines\r\n(Get-content $Output_Filename) | ? {$_.trim() -ne \"\" } | set-content $Output_Filename\r\n \r\n# Done\r\nWrite-Host \"\"\r\nWrite-Host \"Done! Opening file: $Output_Filename\" -ForegroundColor Cyan\r\nWrite-Host \"\"\r\nInvoke-Item $Output_Filename\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"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 Continue reading Powershell script to get a unique list of IP’s added to Exchange 2013 Receive Connectors<\/span>