' This script was originally published in the Exchange Cookbook, ' (http://www.exchangebookcook.com). Written by Paul Robichaux, ' Missy Koslosky, and Devin Ganger. Redistributed with permission ' of the publisher, O'Reilly & Associates. ' This code deletes a given message within an Exchange SMTP queue. ' ------ SCRIPT CONFIGURATION ----- ' The host name of the Exchange server strHostname = "" ' e.g., red-exch02 ' Name of the SMTP queue to search for messages strQueueName = "" ' e.g., 3sharp.com ' Message ID of the message to delete strMessageID = "" ' ------ END CONFIGURATION -------- ' Get the Exchange Namespace WMI object Set objWMIExch = GetObject("winmgmts://" & strHostname &_ "/root/MicrosoftExchangeV2") ' Get the list of queues and process our desired queue Set objQueuesList = objWMIExch.InstancesOf("Exchange_SMTPQueue") For Each objQueueInst in objQueuesList ' Make sure this queue is the one we're looking for; if not, skip it If objQueueInst.QueueName = strQueueName Then strMsgInfo = strMsgInfo & "Queue: " & objQueueInst.QueueName & " (" &_ objQueueInst.QueueID & ")" & VbCrLF Set objMsgsList = objWMIExch.ExecQuery ("Select * From " &_ "Exchange_QueuedSMTPMessage Where ProtocolName='SMTP' And LinkId='" &_ objQueueInst.LinkID & "' And LinkName='" &_ objQueueInst.LinkName & "' And QueueId='" &_ objQueueInst.QueueID & "' And QueueName='" &_ objQueueInst.QueueName &"' And VirtualMachine='" &_ objQueueInst.VirtualMachine & "' And VirtualServerName='" &_ objQueueInst.VirtualServerName & "' And MessageID ='" &_ strMessageID & "'") For each objMsgInst in objMsgsList strMsgInfo = strMsgInfo & " Message " &_ objMsgInst.MessageID & VbCrLF &_ " Sender: " & objMsgInst.Sender & VbCrLF &_ " MessageID: " & objMsgInst.MessageId & VbCrLF objMsgInst.DeleteNoNDR strMsgInfo = strMsgInfo & " Message deleted." & VBCrLF Next End If Next Wscript.Echo strMsgInfo