• subscribe
April 24, 2002 12:00 AM

Troubleshooter: Dismounting an Exchange 2000 Database from the Command Line

Windows IT Pro
InstantDoc ID #24788

I'm writing management scripts for use on our Exchange 2000 Server systems. Do you know of a way to dismount a database from the command line?

Exchange 2000 includes a new set of management interfaces. In addition to the Collaboration Data Objects (CDO) library, Exchange 2000 includes the CDO for Exchange Management (CDOEXM) library. CDOEXM implements several interfaces that let you perform tasks relating to your servers, storage groups (SGs), and databases. Among these interfaces is an object class called IMailboxStoreDB, which has a method called Dismount. Your code needs to get a pointer to the server object, use that object to get a pointer to the mailbox store you want to fiddle with, then use that pointer to call the Dismount method. The Microsoft Developer Network (MSDN) Library offers documentation for IMailboxStoreDB and the rest of the CDOEXM interfaces at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wss/wss/_esdk_reference_cdoexm.asp.



ARTICLE TOOLS

Comments
  • Leon
    7 years ago
    Jun 10, 2005

    I have updated the utility. It now supports Public Folders. Email me to recieve it...

  • Leon
    7 years ago
    Feb 17, 2005

    um - oops. Looks like it wont let me paste it correctly. If you want the code email me at leon_funnell(AT)hotmail(d0t)com...

  • Leon
    7 years ago
    Feb 17, 2005

    Answer:
    a) Learn Vbscript and make a command line utility
    b) Use the one I wrote below:

    ' Name: StoreDB.VBS
    ' Purpose: To Mount, Dismount, or Delete a Mailbox Store (MDB) on Exchange Server
    '
    'Written by Leon Funnell
    'email me at leon_funnell(At)hotmail(d0t)com
    '17/02/2005
    '
    '

    quot = chr(34)

    Set iServer = CreateObject ("CDOEXM.ExchangeServer")
    Set iMDB = CreateObject ("CDOEXM.MailboxStoreDB")

    ' check command line
    GetArgs strMode,strComputerName,strSGName,strMDBName,CorrectSyntax
    If CorrectSyntax Then
    BindMailboxStore strComputerName,strSGName,strMDBName
    Select Case strMode
    Case "mount"
    wscript.echo "Mounting Database " & strMDBName & " in Storage Group " & strSGName & " on " & strComputerName
    iMDB.mount
    Case "dismount"
    wscript.echo "Dismounting Database " & strMDBName & " in Storage Group " & strSGName & " on " & strComputerName
    iMDB.dismount
    Case "delete"
    wscript.echo "Deleting Database " & strMDBName & " in Storage Group " & strSGName & " on " & strComputerName
    iMDB.DataSource.delete
    End Select

    ' Cleanup
    Set iServer = Nothing
    Set iMDB = Nothing
    Else
    DisplayHelp
    wscript.quit
    End If

    Sub BindMailboxStore (strComputerName,strSGName,strMDBName)
    ' Bind to the Exchange Server
    iServer.DataSource.Open strComputerName

    ' Build the first part of the URL to the MailboxStoreDB
    strTemp = "LDAP://" & iServer.DirectoryServer & "/" & "cn=" & strMDBName & ","

    ' Set variant array to the ExchangeServer.StorageGroups
    arrStGroup = iServer.StorageGroups

    ' Look in the StorageGroups array if the StorageGroup with strSGName exists
    If strSGName = "" Then
    ' Add last part to the URL to the MailboxStoreDB
    strMDBUrl = strTemp & iServer.StorageGroups(0)
    Else
    For i = 0 To UBound(arrStGroup)
    If InStr(1, UCase(arrStGroup(i)), UCase(strSGName)) <> 0 Then
    strMDBUrl = arrStGroup(i)
    End If
    Next
    If strMDBUrl <> "" Then
    ' Add last part to the URL to the MailboxStoreDB
    strMDBUrl = strTemp & strMDBUrl
    End If
    End If
    ' Bind to the MailboxStoreDB
    iMDB.DataSource.Open strMDBUrl ', , , adCreateOverwrite
    End Sub


    Sub GetArgs(strMode,strComputerName,strSGName,strMDBName,CorrectSyntax)
    Set Args = WScript.Arguments
    If args.count = 4 Then
    CorrectSyntax = True
    strMode = args(0)
    wscript.echo strmode
    strComputerName = args(1)
    strSGName = args(2)
    strMDBName = args(3)
    Else
    CorrectSyntax = False
    End If
    Select Case lcase(strMode)
    Case "mount","dismount","delete"
    CorrectSyntax = True
    Case "/?","/help","?","help"
    CorrectSyntax = False
    End Select
    End Sub


    Sub DisplayHelp
    wscript.echo "Mounts, Dismounts, or Deletes a Mailbox Store on an Exchange 2000/2003 server"
    wscript.echo ""
    wscript.echo "cscript StoreDB.vbs /? or /Help ----------------------------------- Displays this help screen"
    wscript.echo "cscript StoreDB.vbs Mount Servername StorageGroupName MDBName ----- Mounts Database"
    wscript.echo "cscript StoreDB.vbs Dismount Servername StorageGroupName MDBName -- Dismounts Database"
    wscript.echo "cscript StoreDB.vbs Delete Servername StorageGroupName MDBName ---- Deletes Database"
    wscript.echo ""
    wscript.echo ""
    wscript.echo "Example:"
    wscript.echo ""
    wscript.echo "cscript StoreDB.vbs Mount SERVER1 ""&"First Storage Group""&" ""&"Mailbox Store (SERVER1)""
    wscript.echo ""
    End Sub

  • Michael Shire
    9 years ago
    Oct 23, 2003

    This article doesn't answer the original question. Is it possible to dismount a store from a command line, without programming?

  • brian
    10 years ago
    Aug 05, 2002

    This article was absolutely no help. He answers the problem of mounting X-change DB's from the command line by pointing you to the MSDN and building API objects. So much for the command line!

You must log on before posting a comment.

Are you a new visitor? Register Here
  • SP1?
    I know there is a SP1 for SQL 2008 R2 available....and there is a "feature pack" as well... ...
  • SQL database mirroring
    I have SQL Server 2008 R2 Enterprise 64bit on Windows 2008 R2 Enterprise 64bit.  Each SQL Server has...
  • Dell Compellent Disk Drive
    Does anybody has experience with Dell Compellent Disk Drive? Basically, this system manages all disk...
  • Sql server performance tuning
    I need to find a tool that help me to optimize sql server,queries,improve the performance and solve ...