Create Database (VBScript)

This code can be found in Chapter 6 of Exchange Server Cookbook

Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.

Find out how to download all of the VBScript code from this site.

' This script was originally published in the Exchange Cookbook,
' (http://www.exchangebookcook.com). Written by Paul Robichaux, 
' Missy Koslosky, and Devin Ganger. Redistributed with permission 
' of the publisher, O'Reilly & Associates.

' This script creates a new mailbox database at the specified
' location

' ------ SCRIPT CONFIGURATION ------
 strServerName = "<serverName>"    ' e.g. "BATMAN"	
 strDBName = "<newMDBName>"	' e.g. "SpiffyNewMDB"
 ' ------ END CONFIGURATION ---------


Set theServer = CreateObject("CDOEXM.ExchangeServer")
Set theMDB = CreateObject("CDOEXM.MailboxStoreDB")

' bind to the Exchange server and build the database URL
theServer.DataSource.Open strServerName

 'Get the array list of StorageGroups and turn it into a 
 'target SG name. If you want this in another SG, modify
 'the code to get the correct one either by name or by index.
  strTemp = theServer.StorageGroups
  strTemp1 = Mid(strTemp(0), InStr(2, strTemp(0), "CN"))
  theFirstSG = "CN=" & "First Storage Group" & "," & strTemp1

strURL = "LDAP://" & theServer.DirectoryServer & "/cn=" & strDBName & "," & theFirstSG
theMDB.Name = strDBName
theMDB.DataSource.SaveTo strURL
WScript.Echo "Created new MDB " & strDBName & " at " & strURL
theMDB.Mount
WScript.Echo "Mounted new MDB " & strDBName

This code has been viewed 1490 times.

New from the creators of TechTasks.com: StatSheet.com