Monday, October 12, 2015

Removing Large Amounts of Spam from Exchange Server Queue Database

A customer running Exchange 2010 experienced a large number of spam emails in the submission queue (over 80,000).

All the Spam Emails started with "ID#ALERT#", as a result we ran the following command to clean up any emails with "ID#ALERT#" in the subject.

Get-Message -ResultSize unlimited | Where-Object {$_.Subject -match "ID#ALERT#"} | Remove-Message

Due to the significant amount of spam, the command failed to remove the messages and just hung for hours.  However we could remove messages individually.

We could however list the emails with the following command:

Get-Message -ResultSize unlimited | Where-Object {$_.Subject -match "ID#ALERT#"}

This gave us an idea to write a foreach command to remove each email individually from a CSV file.  First we needed a detailed list with the identity of each spam email so we ran the following command:

Get-Message -ResultSize unlimited | Where-Object {$_.Subject -match "ID#ALERT#"} | select Identity > C:\output.txt

We then formatted the CSV file to ensure we specified a name for the Identity column.  As you see we added "Identity" to the top of the file.

We then ran the Remove-Message command multiple times for each Identity in the CSV file using the following command:

Import-Csv "C:\output.txt" | ForEach-Object {Remove-Message -Identity $_.Identity -confirm:$false}

This ran the Remove-Message command over 80,000 times for each message in the queue and was able to clean it up successfully.


  1. I am Hwa Jurong, a Private Money Lender do you need a loan to start up business or to pay your bills and a corporate financial for real estate and any kinds of business financing. I also offer Loans to individuals,Firms and corporate bodies at 2% interest rate. I give out loan to serious minded people that are interested of loan if interested contact this email: or


    1. windows 8 professional key buy online , windows 10 serial keys product key torrent , use windows 8 product key for windows 10 , office 2013 activation keys , microsoft visio professional 2016 , windows 7 ultimate sp1 activation key , windows key purchase , windows 10 serial keys for installation , sNJcrO

      windows 10 pro key

      office 2013 pro key sale

      cheap visual studio key buy

    2. This comment has been removed by the author.

    3. This comment has been removed by the author.

  2. Thanks for sharing this tool information it is useful to us.
    Outlook Mail

  3. Hello all
    Hacker Services Available
    am looking few years that some guys comes into the market they called themselves hacker, carder or spammer they rip the peoples with different ways and it’s a badly impact to real hacker now situation is that peoples doesn’t believe that real hackers and carder scammer exists. Anyone want to make deal with me any type am available but first I‘ll show the proof that am real then make a deal like
    Wire Bank Transfer
    Western Union,
    Money Gram
    Air Ticket
    Hotel Booking
    Hacking stuff
    Shipping product. serious / needy contact about it.

  4. Hello, Lakewood Financial Institutions is at it again, we give loan to both local and international client in need of a loan. And we give @ 2% rate to all client, so you can contact us via E-mail,

  5. This comment has been removed by the author.

  6. This comment has been removed by the author.