Script to add Public Folder replicas all the way down a subtree

I’m in the process of trying to migrate my public folders from Exchange 2003 to Exchange 2007.  As part of the process (since my public folder database is SO HUGE!) I’m moving small subsets of folders at a time instead of performing a “Move All Replicas” task.

To facilitate this I’m adding the new 2007 pub databases to the replica list of a sub-folder first, allowing replication to happen and then removing the 2003 pub databases from the replica list.

The trick is getting the 2 new 2007 pub databases added to the list without necessarily knowing what’s already in the replica list and doing all of this in a script, not a GUI.

Below is the script I wrote to do this.  I simply type the script name at the PowerShell command line and then pass the path of the root folder I want to start with on the command line.  The script starts from that root folder and adds my 2 new 2007 servers to the list all the way down the tree.

[string]$path = $args[0]
Write-Host $path
$server1 = Get-PublicFolderDatabase -Server servername1
$server2 = Get-PublicFolderDatabase -Server servername2

$folders = Get-PublicFolder $path -Recurse
foreach ($rootfolder in $folders) {
 $rootfolder.Replicas +=$server1.Identity
 $rootfolder.Replicas +=$server2.Identity
 $rootfolder | Set-PublicFolder}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s