Create Public Folder Tree 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 public folder tree on the specified server.
' You also have to specify the public folder database, admin group,
' org name, and domain.

' ------ SCRIPT CONFIGURATION ------
 strServerName = "<serverName>"    ' e.g. "BATMAN"	
 strPFDBName = "<pfDBName>"
 strPFTreeName = "<pfTreeName>"
 strAdminGroup = "<adminGroupName>
 strOrgName = "<orgName>"
 strDomain = "<domain>"		' e.g. "dc=contoso,dc=local"
 ' ------ END CONFIGURATION ---------

Set theServer = CreateObject("CDOEXM.ExchangeServer")
Set theNewTree = CreateObject("CDOEXM.FolderTree")
Set theDSE =  GetObject("LDAP://RootDSE")
Set thePFDB = CreateObject("CDOEXM.PublicStoreDB")

' create the public tree. You could dynamically get the AG and org
' name but for simplicity we're defining them statically
strTreeURL = "LDAP://CN=" & strPFTreeName & ",CN=Folder Hierarchies" & _
   ",CN=" & strAdminGroup & ",CN=Administrative Groups,CN=" & strOrgName & _
   ",CN=Microsoft Exchange,CN=Services,CN=Configuration," & theDSE.Get("defaultnamingcontext")
theNewTree.name = strPFTreeName 
theNewTree.DataSource.SaveTo strTreeURL
thePFDB.Name = strPFDBName
thePFDB.FolderTree = strTreeURL

' Find the first SG
theServer.DataSource.Open strServerName
For Each sg In theServer.StorageGroups
  theFirstSG = sg
  Exit for
Next
' Create the URL to the new PF, then create and mount it
strPFURL = "LDAP://" & theServer.DirectoryServer & "/CN=" & strPFDBName & "," & theFirstSG
thePFDB.DataSource.SaveTo strPFURL
thePFDB.Mount
WScript.Echo " created new PF tree at " & strPFURL

This code has been viewed 2322 times.

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