a previous post<\/a><\/p>\n<\/p>\n
<#\r\n.NAME\r\n Remove-RelayIP-Exchange2013.ps1\r\n.DESCRIPTION\r\n Powershell script that allows you to remove a single IP address from 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.1\r\n.Author\r\n Kyle McDonald\r\n.Compatibility\r\n Exchange 2013\r\n.Release Date\r\n July 2014\r\n#>\r\n\r\ncls\r\n \r\n$MailHost = \"mailhost.contoso.com\"\r\n \r\n# Text in Receive Connector name to filter on. Leave blank to apply to all Connectors\r\n# EG $RcvConnectorFilter = \"\"\r\n# EG $RcvConnectorFilter = \"relay\"\r\n$RcvConnectorFilter = \"relay\"\r\n \r\n# Check for an open connection to Exchange\r\n$OpenSession = Get-PSSession | Where-Object {$_.ComputerName -eq \"$MailHost\" -and $_.State -eq \"Opened\"} | select ComputerName -expandproperty ComputerName\r\nIF ([string]::IsNullOrEmpty($OpenSession)) \r\n {}\r\n ELSE \r\n { $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http:\/\/$MailHost\/PowerShell\/ -Authentication Kerberos ; Import-PSSession -disablenamechecking $Session }\r\n \r\n# Get all Receive Connectors\r\nWrite-Host \"\"\r\nWrite-Host \"Getting list of Receive Connectors...\"\r\nIF ([string]::IsNullOrEmpty($RcvConnectorFilter)) \r\n { $RcvConnectors = Get-ReceiveConnector | Select -ExpandProperty Identity }\r\n ELSE \r\n { $RcvConnectors = Get-ReceiveConnector | Where-Object {$_.Identity -like \"*$RcvConnectorFilter*\"} | Select -ExpandProperty Identity }\r\n \r\n# List Receive Connectors Found\r\nWrite-Host \"Receive Connectors Found:\" -ForegroundColor Cyan\r\n foreach ($element in $RcvConnectors) {Write-Host $element}\r\n \r\n# Ask for IP that needs to be removed\r\nWrite-Host \"\"\r\n $IPAddress = Read-Host \"Please enter the IP Address to remove from relay\"\r\n\r\n# Test IP is valid\r\n$pattern = '^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$'\r\n$IPOK = $IPAddress -match $pattern\r\nIF ($IPOK -eq $false) {\r\n Write-Warning (\"IP Address {0} is not a valid IPv4 address.\" -f $IPAddress)\r\n $IPAddressCont = \"n\"\r\n }\r\n ELSE\r\n {Write-host \"IP Address\"$ipAddress \"is valid.\" -ForegroundColor Green\r\n # Prompt to continue\r\n Write-Host \"Are you sure you would like to remove \" -NoNewLine ; Write-Host $IPAddress -ForegroundColor Green -NoNewLine ; $IPAddressCont = Read-Host \" from the above receive connectors? (Y\/N)\" \r\n }\r\n \r\nWrite-Host \"\"\r\n IF ($IPAddressCont -eq \"y\")\r\n { Write-Host \"Starting ...\" -ForegroundColor Green\r\n foreach ($element in $RcvConnectors) {\r\n Write-Host \"Removing IP Address:\" $IPAddress \" from \"$element -ForegroundColor Cyan\r\n $Rcnn = Get-ReceiveConnector \"$element\"\r\n $Rcnn.RemoteIPRanges -= $IPAddress\r\n Set-ReceiveConnector \"$element\" -RemoteIPRanges $Rcnn.RemoteIPRanges\r\n }\r\n Write-Host \"Done!\" -ForegroundColor Cyan\r\n }\r\n ELSE\r\n { Write-Host \"Stopping!\" -ForegroundColor Red }\r\n \r\n#Give the user a choice to run the script again\r\ndo { Write-Host \"\"\r\n $userMenuChoice = read-host -prompt \"Would you like to do this again? (Y\/N)\"\r\n } until ($userMenuChoice -eq \"y\" -or $userMenuChoice -eq \"n\")\r\n \r\n}\r\nwhile ($userMenuChoice -eq \"y\")\r\n# LoopMain End\r\nWrite-Host \"Bye!\"\r\nWrite-Host \"\"\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"A simple script to compliment a previous post<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[30],"tags":[],"yoast_head":"\n
Remove IP from Exchange Relay Connectors - Kyle McDonald<\/title>\n \n \n \n \n \n \n \n \n \n \n \n \n \n