Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script to mount/dismount mail store 1

Status
Not open for further replies.

withanh

IS-IT--Management
Dec 17, 2008
221
US
I found this script online and was wondering if anyone has used it (or something similar) and what their experience was with it.

Thanks!

h
Code:
' 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 "&quot&"First Storage Group"&quot&" "&quot&"Mailbox Store (SERVER1)"&quot
  WScript.echo ""
End Sub
 
To build it into a batch file i.e.:

dismount store
offline defrag
mount store

That way when the offline defrag is done running at 3am, the store will mount without any interaction.

 
Online defrag happens overnight without dismounting.

Offline defrag should NOT be done regularly and should ONLY be done manually.
 
I know and understand the difference between online defrag and offline defrage.

I moved some mailboxes out of one mailstore into another. Now my mailstore is 36GB total and 25GB free. This is clearly a case for offline defrag.

Thanks
 
He just doesnt want to be up at 3AM to remount the store. :)

________________________________________
Achieving a perception of high intelligence level can only be limited by your manipulation skills of the Google algorithm!
 
Exactly! I just want it to remount the store when the defrag is done.

 
Autoremounting after an offline defrag or even in the middle of it if the timing is wrong.

OK, enjoy...just not on my farm.
 
It's in a batch file, the mount command won't run until the defrag command is done. I'm not worried about that, I just want to know if anyone else has used a script such as the one I posted and what their experiences were with the script. i.e. did it take any longer than manually mounting/dismounting, etc.

Thanks,

h
 
Have never used a script as the dismount is only "right click, choose dismount". Similarly for mounting. Only time I'd run it is prior to an offline defrag which I've not needed to do for ages (like years).
 
Offline defrag......

The last time I did one of those was 19....

create a new DB, move the remaining mailboxes, and kill the old one. MUCH faster, and doesn't require downtime.

Pat Richard MVP
Plan for performance, and capacity takes care of itself. Plan for capacity, and suffer poor performance.
 
58sniper said:
create a new DB, move the remaining mailboxes, and kill the old one. MUCH faster, and doesn't require downtime.
Great idea, unfortunately we're already at 4 mail stores and can't add any more. Plus I'm a little gun shy right now about moving any more users, it's thrown a huge wrench at my BES and only about 1/2 of the moved users are getting emails on their BlackBerry's.

 
I like the 58sniper idea! perfect! *STAR*

________________________________________
Achieving a perception of high intelligence level can only be limited by your manipulation skills of the Google algorithm!
 
Great idea, unfortunately we're already at 4 mail stores and can't add any more.
Then move the existing users into the other stores, delete the bloated store, create a new one, and move the users back.

The Blackberry issue is something to take up with their support. You shouldn't suffer operational downtime just from moving a mailbox. Another reason why I'd rather use an etch-a-sketch than a Blackberry.

Pat Richard MVP
Plan for performance, and capacity takes care of itself. Plan for capacity, and suffer poor performance.
 
After themove on Exchange the BES server will update eventually or you can restart BES Services within its GUI

________________________________________
Achieving a perception of high intelligence level can only be limited by your manipulation skills of the Google algorithm!
 
I know BES will eventually catch up, but I restarted BES yesterday at 4:30am, BES was still not 100% until after 4pm. I have over 100 users on BES and the 1/2 that weren't working were pissed their BlackBerry's weren't working all day yesterday, including the boss's boss's boss. That's why I'm gun shy about moving them.

But, we're digressing from the original point of the thread. Hopefully it won't come up again, because my mail stores are finally how I want them. I just want to know about experiences with the script. And since it seems no one has any experience with it...

I do like 58sniper's solution as well, the idea of no downtime on the mail store for the offline defrag is good. I'll remember that if I ever have to do this again.

h
 
Not just Pat's idea - it is in wide use.

Depending on your BES implementation, sometimes a mailbox move will mean that you end up having to reinitialise BES accounts.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top