Motivation: Making the Systems Engineers life easier.

Clearing Exchange Mail Queues using PowerShell

Microsoft Exchange

Clearing Exchange Mail Queues using PowerShell

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:

  1. Login to the Exchange Server.
  2. Right Exchange Management Shell and Click on Run ISE as Administrator
  3. 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.

 

Leave your thought here

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Topics