該任務是從Exchange Server接收連接器中刪除IP地址。刪除IP地址和IP地址範圍在Exchange Admin Center中,一個一個接一個時間將花費大量時間。實現目標的最快方法是使用PowerShell。在本文中,您將學習如何使用PowerShell腳本從Exchange接收連接器中刪除遠程IP地址。
在Exchange Admin Center中檢查遠程IP地址
登錄到交換管理中心。單擊功能窗格郵件流並跟隨接收連接器在標籤中。選擇具有接收連接器的Exchange Server從中刪除遠程IP地址。單擊列表視圖中的接收連接器,然後單擊工具欄中的編輯圖標。
在我們的示例中,它是Exchange Server EX02-2016.EXOIP.LOCAL和SMTP繼電器接收連接器。

我們可以看到存在的遠程IP地址。


可以在交換管理中心中逐一刪除IP地址,但不建議進行。這很耗時,您可能會錯過一個IP地址。
我們將如何快速刪除Exchange接收連接器中的IP地址?Powershell救援。
準備IP地址CSV文件
您是否已經有要刪除的IP地址列表?那太棒了。如果不是,則可以創建一個CSV文件,如下屏幕所示。
這是具有IP地址的CSV的樣子。前兩個是幾個IP地址範圍,其他是單個IP地址。確保使用相同的CSV文件名和標題“表達”。


將CSV文件放在名稱relayipsexpression.csv在C:溫度文件夾。


運行Exchange Management Shell作為管理員。驗證PowerShell可以使用該文件讀取CSV文件進口-CSVcmdlet。
Import-Csv "C:tempRelayIPsExpression.csv"
輸出出現在下面。
Expression
----------
192.168.1.70-192.168.1.80
192.168.1.75-192.168.1.80
192.168.1.99
192.168.1.174
192.168.1.221
192.168.1.222
192.168.1.234
192.168.1.235
192.168.1.240
從接收連接器PowerShell腳本中刪除IP地址
下載remove-ipreceiveconnector.ps1 PowerShell腳本並將其放入C:腳本文件夾。
確保文件未阻止以防止運行腳本時的錯誤。在運行PowerShell腳本時,請在文章中閱讀更多信息。
另一個選擇是將下面的代碼複製並粘貼到記事本中。給它名字remove-ipreceiveconnector.ps1並將其放在C:腳本文件夾。
# Fill in the path of your csv file and receive connector
$Csv = "C:tempRelayIPsExpression.csv"
$RC = "EX02-2016SMTP Relay"
# Import IP addresses from CSV file
$IPs = Import-Csv $Csv
# Get receive connector
$RCon = Get-ReceiveConnector $RC
# Get receive connector remote IP addresses
$RemoteIPRanges = $RCon.RemoteIPRanges
# Loop through each IP address
foreach ($IP in $IPs) {
$IPEx = $IP.Expression
# Check if IP address exists
if ($RemoteIPRanges -contains $IPEx) {
$RemoteIPRanges = $RemoteIPRanges | Where-Object { $_ -ne $IPEx }
# Remove the -WhatIf parameter after you tested and are sure to remove the remote IP addresses
Set-ReceiveConnector $RC -RemoteIPRanges $RemoteIPRanges -WhatIf
Write-Host "IP address $($IPEx) removed from receive connector $($RC)" -ForegroundColor Green
}
else {
Write-Host "IP address $($IPEx) does not exist in receive connector $($RC)" -ForegroundColor Yellow
}
}
運行Exchange Management Shell作為管理員,並運行PowerShell腳本以刪除IP地址。該腳本將通過列表中的每個IP地址。
筆記:很高興知道 - whatif參數是在腳本中添加的。如果您運行腳本,則環境中不會發生任何事情。您將獲得一個輸出,顯示將會發生什麼。
在我們的示例中,該腳本將嘗試批量將9個IP地址刪除到指定的接收連接器中。它不會刪除一個IP地址,因為它不存在接收連接器中。
C:scripts.Remove-IPReceiveConnector.ps1
運行腳本後,確認IP地址和接收連接器。
What if: Configuring Receive connector "EX02-2016SMTP Relay".
IP address 192.168.1.70-192.168.1.80 removed from receive connector EX02-2016SMTP Relay
What if: Configuring Receive connector "EX02-2016SMTP Relay".
IP address 192.168.1.75-192.168.1.80 removed from receive connector EX02-2016SMTP Relay
What if: Configuring Receive connector "EX02-2016SMTP Relay".
IP address 192.168.1.99 removed from receive connector EX02-2016SMTP Relay
What if: Configuring Receive connector "EX02-2016SMTP Relay".
IP address 192.168.1.174 removed from receive connector EX02-2016SMTP Relay
What if: Configuring Receive connector "EX02-2016SMTP Relay".
IP address 192.168.1.221 removed from receive connector EX02-2016SMTP Relay
What if: Configuring Receive connector "EX02-2016SMTP Relay".
IP address 192.168.1.222 removed from receive connector EX02-2016SMTP Relay
IP address 192.168.1.234 does not exist in receive connector EX02-2016SMTP Relay
What if: Configuring Receive connector "EX02-2016SMTP Relay".
IP address 192.168.1.235 removed from receive connector EX02-2016SMTP Relay
What if: Configuring Receive connector "EX02-2016SMTP Relay".
IP address 192.168.1.240 removed from receive connector EX02-2016SMTP Relay
我們可以看到一切看起來都很好,我們可以刪除-如果什麼範圍。
在第23行,刪除-如果什麼來自PowerShell腳本的參數並重新運行腳本以從Exchange接收連接器中刪除IP地址。
C:scripts.Remove-IPReceiveConnector.ps1
輸出出現在下面。
IP address 192.168.1.70-192.168.1.80 removed from receive connector EX02-2016SMTP Relay
IP address 192.168.1.75-192.168.1.80 removed from receive connector EX02-2016SMTP Relay
IP address 192.168.1.99 removed from receive connector EX02-2016SMTP Relay
IP address 192.168.1.174 removed from receive connector EX02-2016SMTP Relay
IP address 192.168.1.221 removed from receive connector EX02-2016SMTP Relay
IP address 192.168.1.222 removed from receive connector EX02-2016SMTP Relay
IP address 192.168.1.234 does not exist in receive connector EX02-2016SMTP Relay
IP address 192.168.1.235 removed from receive connector EX02-2016SMTP Relay
IP address 192.168.1.240 removed from receive connector EX02-2016SMTP Relay
驗證您的工作
運行PowerShell腳本後,我們可以確認IP地址已從接收連接器中成功刪除。
筆記:*遠程網絡設置中的IP地址在Exchange Admin Center中將按添加日期對IP地址進行排序。您始終可以單擊IP地址以對IP地址進行排序。
另請閱讀:使用PowerShell在交換中獲取所有SMTP(電子郵件)地址


讓我們列出帶有PowerShell的接收連接器中的IP地址,然後按IP地址進行排序。
(Get-ReceiveConnector -Identity "EX02-2016SMTP relay").RemoteIPRanges | Sort-Object | Format-Table
下面的輸出出現。
LowerBound UpperBound Netmask CIDRLength RangeFormat Size Expression
---------- ---------- ------- ---------- ----------- ---- ----------
192.168.1.100 192.168.1.100 SingleAddress ::1 192.168.1.100
就是這樣!使用PowerShell工作從接收連接器中刪除IP地址。這個為您服務嗎?
結論
您了解瞭如何從Exchange接收連接器中刪除遠程IP地址。使用PowerShell腳本從接收連接器中刪除IP地址非常好。通過從CSV文件中提取IP,您可以確保沒有錯誤。此方法將節省您的時間和精力。
您喜歡這篇文章嗎?您可能還喜歡配置Office 365 SMTP繼電器。不要忘記關注我們並分享這篇文章。