Friday, 12 August 2011

Exchange 2003 SP2 - Re-mount oversized dismounted store automatically

For those of you unfortunate enough to still be stuck with Exchange 2003 SP2 and it's 75Gig store limit,if you cannot apply best practices to lower mailbox sizes you may want to consider trying the following scriptlet i've customized.

'**********************************************************************
' Name: Store.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
'modified by LDean -- ldean[at]quikteks[dot]com
'11/10/2008
'modified by PsyWulf
'07/08/2010

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
Case "status"
dim sStoreStatus
If iMDB.Status = 0 Then
  wscript.echo "Status 0 - Mounted"
  wscript.quit(0)
 ElseIf iMDB.Status = 1 Then
  wscript.echo "Status 1 - Dismounted"
  wscript.echo "Attempting to mount"
  iMDB.mount

  wscript.quit(1)
 ElseIf iMDB.Status = 2 Then
  wscript.quit(2)
 ElseIf iMDB.Status = 3 Then
  wscript.quit(3)
 Else
  wscript.quit(4)
 End If
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 Store.vbs /? or /Help ----------------------------------- Displays this help screen"
wscript.echo "cscript Store.vbs Mount Servername StorageGroupName MDBName ----- Mounts Database"
wscript.echo "cscript Store.vbs Dismount Servername StorageGroupName MDBName -- Dismounts Database"
wscript.echo "cscript Store.vbs Delete Servername StorageGroupName MDBName ---- Deletes Database"
wscript.echo "cscript store.vbs status Servername StorageGroupName MDBName ---- Checks status of database"
wscript.echo ""
wscript.echo ""
wscript.echo "Example:"
wscript.echo ""
wscript.echo "cscript Store.vbs Mount SERVER1 "&quot&"First Storage Group"&quot&" "&quot&"Mailbox Store (SERVER1)"&quot
wscript.echo ""
End Sub
'**********************************************************************

Copy this into a file called store.vbs and save it to the Server. Then create a batch file with the following in

cscript c:\store.vbs status servername "storage group name"  "Mailbox Store name"
 Set it to run daily or hourly even. What the script does is check the Exchange store status,if dismounted it attempts to re-mount the store

Hope this helps

No comments:

Post a Comment