I always find that my customers hit a stumbling block when it comes to the flexibility of move public folders. There are a lot of good articles on the internet that helps admins move public folders and I cover some of those options in this blog however, in large environments I couldn’t find any posts that provided the flexibility needed for replication of PFs. In light of this need, I created a script that allows admins to modify the PFs that want to migrate with the ability to choose which databasesfolders to replicate during the migration and more importantly the ability to replica public folder that have spaces and special characters. If you have any questions or would like me to add more options to the script let me know. Thanks and happy Exchanging!!!!

1. The first thing we need to do is get a list of the public folders that are homed on the Exchange 2003 public folder server. You can use either PFDAVADMIN (http://www.microsoft.com/downloads/details.aspx?FamilyID=635BE792-D8AD-49E3-ADA4-E2422C0AB424&displaylang=en) or by running the get-publicfolder command in powershell.

a. Get-publicfolder -recurse |fl name,replicas > c:publicfolders.txt

b.  Your output file will look like this:

Name     : IPM_SUBTREE

Replicas : {}

Name     : IT

Replicas : {, Public Folder Store (E2K3)}

Name     : HR

Replicas : {Public Folder Store (E2K3)}

Name     : HR Calendar

Replicas :  {Public Folder Store (E2K3)}

Name     : Payroll

Replicas : {Public Folder Store (E2K3)}

Name     : Questions for the CIO

Replicas : {Public Folder Store (E2K3)}

Name     : VIP

Replicas : {Public Folder Store (E2K3)}

Option 1: Microsoft’s AddReplicaToPFRecursive.ps1

1. Use the AddReplicaToPFRecursive.ps1 script to add the public folders to Exchange 2007. This script is added when we installed Exchange 2007 and is located in the script directory under the default installation path. Here is a brief explanation of the script from http://technet.microsoft.com/en-us/library/aa997966.aspx:

Add a server to the replication list. AddReplicaToPFRecursive.ps1 This script adds a new server to the replication list for a public folder and all the folders beneath it in the hierarchy. If the server is already listed in the replication list for a folder, nothing is changed for that folder. This script accepts the following parameters:

2. The steps below will walk you through the process of using the AddReplicaToPFRecursive.ps1. In my lab I used my public folder HR as an example.

a. Notice that after we run the command below the output only shows the Exchange 2003 public folder store

Output from get-publicfolder HR –recurse |fl name,replicas

Name     : HR

Replicas : { Public Folder Store (E2K3)}

Name     : HR Calendar

Replicas : {Public Folder Store (E2K3)}

b. Now we want to run the powershell script to add the Exchange 2007 public folder store

AddReplicaToPFRecursive.ps1 -TopPublicFolder “HR” -ServertoAdd E2K7

c. Notice the Exchange 2007 public folder store has been added to the top level folder and any sub folders

Output from get-publicfolder HR –recurse |fl name,replicas

Name     : HR

Replicas : {Public Folder Database, Public Folder Store (E2K3)}

Name     : HR Calendar

Replicas : { Public Folder Store (E2K3)}

Note: Notice that the HR Calendar folder was not updated. We will talk about this more later in the blog post

Option 2: User Set-PublicFolder Command

 

1. If you would like to add a replica for one folder at a time you can use the set-publicfolder command in powershell. This time in my lab I’m going to use David’s Cal to add the Exchange 2007 PF database. If there are subfolders under David’s Cal those folders will not be modified.

Set-PublicFolder “David’s Cal” -UseDatabaseReplicationSchedule: $False -Replicas “E2K3Public Folder Store (E2K3)”,”E2K7Public Folder Database”

b. Then we can run the get-publicfolder command again to ensure the public folder has been replicated

get-publicfolder “David’s Cal” –recurse |fl name,replicas

Name     : David’s Cal

Replicas : {Public Folder Database, Public Folder Store (E2K3)}

 

Option 3: Custom Powershell Script

 

The last option is to use the powershell commands below and import the public folders from a csv file. The one issue that I have with the AddReplicaToPFRecursive.ps1 is that it will not work if there is a space or a special character in the name filed. It is also not a flexible script. What I have done is written my own powershell script that will allow you to move PFs base on your environment needs.

1. We want to get a list of the subfolders under HR

get-publicfolder “HR” -Recurse | fl identity, replicas > publicfolder.txt

Identity : HR

Replicas : { Public Folder Store (E2K3)}

Identity : HRHR Calendar

Replicas : {Public Folder Store (E2K3)}

2. Now we want to take the txt file and import the file to Excel and make some modifications (Please note you will need to add another column for each pf database you wish to add to the replica list).

3. After you convert the file to CSV, if you open the file with Notepad the structure should look like the example below with three header columns, Name, Replica1, and Replica2.

Notepad:

Name,Replica1,replica2

“HR”,E2K3Public Folder Store (E2K3),E2K7Public Folder Database

“HRHR Calendar”,E2K3Public Folder Store (E2K3),E2k7Public Folder Database

 

4. Copy the code below and create a ps1 script in the same directory as the csv file you created in the step above. Run the script in powershell and the public folders will be replicated to Exchange 2007.

$Logfile = “c:mailboxmovelogfile.txt”

$GC = “dcname”

$error.Clear()

$Publicfolderfile = import-csv c:pf.csv

foreach ($PF in $publicfolderfile)

{

$PFName = $pf.name

$Replicadatabase1 = $PF.replica1

$Replicadatabase2 = $PF.replica2

$message = “moving user -> ” + $PFName

$date = get-date

write-output $date $message | out-file -filepath $Logfile -append -noclobber

Set-PublicFolder  -id $PFName -UseDatabaseReplicationSchedule: $False -Replicas $Replicadatabase1, $Replicadatabase2

}

5. Now we want to ensure the script worked so we will again run get-public folder to confirm

get-publicfolder “HR” -Recurse | fl identity, replicas > publicfolder.txt

Name     : HR

Replicas : {Public Folder Database, Public Folder Store (E2K3)}

Name     : HR Calendar

Replicas : { Public Folder Database , Public Folder Store (E2K3)}

 

To monitor public folder replication is working follow the directions in this article http://msexchangeteam.com/archive/2007/06/25/445429.aspx under How can I tell if public folder data has replicated to Exchange 2007?