Purge a Mailbox from Exchange2003 programatically using C# or VB.net

HI experts

How do purge a mailbox of a user (not disabe) from Exchange server 2003 programatically using C# or VB.net

I am able to disable the Exchange mailbox of a user using the code below ..I added the referance CDOEXM to code

                        Try
                                UserMailbox = ObjExchange.NativeObject
                                UserMailbox.DeleteMailbox()
                                ObjExchange.CommitChanges()
                                MbxDel = "Deleted"
                            Catch ex As Exception
                                MbxDel = "Error"
                                MbxDelErr = ex.Message
                            End Try

After doing lot of google ...i came to know that Purge() will delete the user mailbox perminently from Exchange Server 2003
 so i tried the below  code ...its not working

                        Try
                                UserMailbox = ObjExchange.NativeObject
                                UserMailbox.Purge() 'Delete mailBox
                                ObjExchange.CommitChanges()
                                MbxDel = "Purged"
                            Catch ex As Exception
                                MbxDel = "Error"
                                MbxDelErr = ex.Message
                            End Try

Its not doing any thing...can any one plz help me ....
bobby010606Asked:
Who is Participating?
 
RameshSCommented:
The documentation of the Purge method in  Exchange_Mailbox WMI class says that the method is available only if the mailbox is disconnected.

Also check the following links.

How to selectively purge mailboxes using a script (Exchange 2003) – Another go

Reporting on Disconnected mailboxes and showing when they will be purged in Exchange 2003
0
 
RameshSCommented:

Try Exchange_Mailbox WMI class which has properties that return information about Microsoft Exchange mailboxes. The Purge method of this class removes the mailbox from the store permanently.
0
 
bobby010606Author Commented:
Tankx ramesh ...plz give me some time i will get back u
0
 
MegaNuk3Commented:
Here is some simple code to purge a selected disconnected(already deleted) mailbox.

' From the book "Active Directory, Third Edition" 
' ISBN: 0-596-10173-2

' This code purges a deleted mailbox.
Option Explicit
Dim strComputer, strMailbox, objWMI, objDiscMbx, objMbx
' ------ SCRIPT CONFIGURATION ------
strComputer = "<Exchange Server>" 'e.g. ExchServer2
strMailbox = "<Mailbox display name>"    'e.g. "Test, User"
' ------ END CONFIGURATION ---------

set objWMI = GetObject("winmgmts:\\" & strComputer & _
                       "\root\MicrosoftExchangeV2")
set objDiscMbx = objWMI.ExecQuery("Select * from Exchange_Mailbox WHERE " _
                              & "MailboxDisplayName='" & strMailbox & "'",,48)
for each objMbx in objDiscMbx
  objMbx.Purge
next
Wscript.Echo "Successfully purged mailbox."

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.