Recipe 6.6. Deleting a DatabaseProblemYou need to remove a database you no longer need. SolutionUsing a graphical user interface
Using VBScript' This code removes the specified mailbox database from its ' parent storage group without touching the on-disk files ' ------ SCRIPT CONFIGURATION ------ strServerName = "<serverName>" ' e.g., "BATMAN" strMDBName = "<mdbName>" ' ------ END CONFIGURATION --------- Set theServer = CreateObject("CDOEXM.ExchangeServer") ' To delete a public folder database here, just change this class ref ' to CDOEXM.PublicStoreDB Set theMDB = CreateObject("CDOEXM.MailboxStoreDB") ' bind to the Exchange server and build the database URL theServer.DataSource.Open strServerName arrSG = theServer.StorageGroups theFirstSG = arrSG(0) strURL = "LDAP://" & theServer.DirectoryServer & "/cn=" & strMDBName & "," & theFirstSG theMDB.Name = strMDBName theMDB.DataSource.Open strURL theMDB.DataSource.Delete WScript.Echo "Database deleted." DiscussionWhen you delete a database file, you're severing its relationship with its parent SG, as well as deleting the corresponding AD object. However, neither ESM nor CDOEXM removes the actual database files from the filesystem. This is a useful protective measure, since you can easily create a new database with the same name, dismount it, and replace its files with the original database files. Using VBScriptThe code in this script only works with mailbox databases because it uses the MailboxStoreDB object from CDOEXM. To make it work with public databases, you need to modify it to use the PublicStoreDB object instead. In either case, the code for deleting a database is similar to that used for creating a database; the difference is that you must bind to the MailboxStoreDB or PublicStoreDB object and use its Delete method to remove the database object instead of just instantiating the object and then using the SaveTo method. See AlsoRecipes Recipe 6.4 and Recipe 6.5 for creating mailbox and public folder databases |