It happens sometimes due to Exchange misconfiguration, there could be a spoof email attack which means Exchange Server sends out spam emails using external sources or any other reason. In this article I will only show you how can we remove the mail queue in bulk through PowerShell ISE without sending NDR (Non Delivery Report).
Solution:
- Login to the Exchange Server.
- Right Exchange Management Shell and Click on Run ISE as Administrator
- Run the below mentioned script and it will clear the mail queue in bulk.
$Servers = “EXCH01″,”EXCH02” #Enter the name of all CAS servers
foreach ($server in $servers)
{
$retryqueues = get-queue -Server $server -filter {Status -eq “Retry”}
foreach ($queue in $retryqueues)
{
Get-Message -Queue $queue.identity | Remove-Message -WithNDR $false -Confirm:$false
}
}
The above script you will have to run multiple times but it will clear the mail queues instead of clearing them manually.