How to to count and dismount data stores via
command line
The following script posted with permissions
from Leon Funnell
' 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)
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
========================================================
The following script posted with permissions
from Ronen Gabbay
There is no command line for dismounting the Exchange database
But you can use VBscript , I wrote one You can customize it and
use it in your script.
For VBscript Remove the input boxes and put your own parameters.
----------------------------------------------------------------------------------------------
Dim strMDBName
Dim strSGName
Dim strComputerName
Dim strAdmGrpName
Dim OrgName
Dim LdapDc
strMDBName = InputBox ("Name of the MDB to be dismounted","Mailbox Store
Name","Mailbox store (Server-A)")
strSGName = InputBox ("Name of the storage group that contains the
MDB","Storage Grop name","First storage group")
strComputerName = InputBox ("Name of the Exchange 2000 server","Server
Name","Server-a")
strAdmGrpName = InputBox ("Name Of the administrative group","Admin Group
name","First Administrative Group")
OrgName = InputBox ("Enter the Organization Name","Organization","NorthWind
Traders")
LdapDc = InputBox ("Enter LDAP Domain
Name","Dc=Domain,Dc=msft","DC=NorhWind,DC=Traders")
' Sub DismountMailboxStoreDB (strMDBName,strSGName,strComputerName )
Dim iMDB
Dim iServer
Dim strTemp
Dim strMDBUrl
Dim arrStGroup()
set iServer = CreateObject ("CDOEXM.ExchangeServer")
set iMDB = CreateObject ("CDOEXM.MailboxStoreDB")
iServer.DataSource.Open strComputerName
WScript.echo iServer.DirectoryServer
' Build the URL to the MailboxStoreDB
strMDBUrl =
"LDAP://"&iServer.DirectoryServer&"/"&"cn="&strMDBName&",cn="&strSGName&",cn
=InformationStore,cn="&strComputerName&",CN=Servers,CN=" &strAdmGrpName&
",CN=Administrative Groups,CN="&OrgName&",CN=Microsoft
Exchange,CN=Services,CN=Configuration,"& LdapDc
WScript.echo "the url is " & strMDBUrl
'e.g strMDBUrl = "ldap://CN=Mailbox Store (SERVER-A),CN=First Storage
Group,CN=InformationStore,CN=SERVER-A,CN=Servers,CN=First Administrative
Group,CN=Administrative Groups,CN=NorthWind Traders,CN=Microsoft
Exchange,CN=Services,CN=Configuration,DC=NorhWind,DC=Traders"
'Bind to the MailboxStoreDB
iMDB.DataSource.Open strMDBUrl
'Dismount the MailboxStoreDB
iMDB.Dismount(30)
WScript.echo "The database "& strMDBName & " was seccessfuly dismounted"
'Cleanup
Set iServer = Nothing
Set iMDB = Nothing
' End Sub
|