Mount/Dismount/Delete a Mailbox Store from the Command Line

Name: StoreDB
Purpose: To Mount, Dismount, or Delete a Mailbox Store or Public Folder (MDB) on Exchange Server
Input: strMDBName = contains the name of the MDB to be dismounted
strType = public or private
strSGName = contains the name of the storage group that contains the MDB
strComputerName = contains the name of the Exchange 2000 server
Written by Leon Funnell
email me at: leon_funnell(At)hotmail(d0t)com

Updated 10/06/2005 to support Public Folders

————————————————————————————————————–

quot = chr(34)

Set iServer = CreateObject (“CDOEXM.ExchangeServer”)

‘ check command line
GetArgs strMode,strType,strComputerName,strSGName,strMDBName,CorrectSyntax
Select Case strType
Case “public”
Set iMDB = CreateObject (“CDOEXM.PublicStoreDB”)
Case “private”
Set iMDB = CreateObject (“CDOEXM.MailboxStoreDB”)
End Select
If CorrectSyntax Then
BindMailboxStore strComputerName,strSGName,strMDBName
Select Case strMode
Case “mount”
wscript.echo “Mounting ” & strType & ” Database ” & strMDBName & ” In Storage Group ” & strSGName & ” On ” & strComputerName
iMDB.mount
Case “dismount”
wscript.echo “Dismounting ” & strType & ” Database ” & strMDBName & ” in Storage Group ” & strSGName & ” on ” & strComputerName
iMDB.dismount
Case “delete”
wscript.echo “Deleting ” & strType & ” 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,strType,strComputerName,strSGName,strMDBName,CorrectSyntax)
Set Args = WScript.Arguments
If args.count = 5 Then
CorrectSyntax = True
strMode = lcase(args(0))
strType = lcase(args(1))
strComputerName = lcase(args(2))
strSGName = lcase(args(3))
strMDBName = lcase(args(4))
Else
CorrectSyntax = False
End If
Select Case lcase(strMode)
Case “mount”,”dismount”,”delete”
CorrectSyntax = True
Case “/?”,”/help”,”?”,”help”
CorrectSyntax = False
End Select
Select Case lcase(strType)
Case “private”,”public”
CorrectSyntax = True
Case “/?”,”/help”,”?”,”help”
CorrectSyntax = False
End Select
End Sub

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

About The Author

Leave a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Scroll to Top