Script: Get-PFInfo.ps1, Fix-PFSchedule.ps1 & some PF replication troubleshooting info

I’m currently working on a Exchange 2007 to 2010 migrations and the client has about 32K and 600 GB of Public Folders. Getting these to replicate has been a big issue, mainly due to issues with replication not happening as expected. I’ve added the target server as a replica, but folders still didn’t fully replicate.

One of the first things required was a script to get the item and size info for each folder from each server so I could check if items were replicated. After running the script below, which started out just as a long cmdlet, I found many folders didn’t replicate.

After removing, re-adding replicas, doing Update-PublicFolder, and other things they still didn’t replicate. I was finally able to get them to replicate after resetting the UseDatabaseReplicationSchedule AND ReplicationSchedule attributes on the problematic folders using a cmdlet like this:
Get-PublicFolder “\Bad Folder” -ResultSize Unlimited -Recurse | set-publicfolder -UseDatabaseReplicationSchedule $False -ReplicationSchedule “Friday.4:00 PM-Monday.4:00 AM”

I looked into the settings on the Public Folders and most, but not all, were using the default replication scheduled but also had the ReplicationSchedule attribute set. The ones that did have a schedule set should have allowed the folders to replicate. All of the PFs that weren’t replicating were only on once server before the new 2010 ones were added, so replication issues hadn’t come up before.

After doing this the folders finally did replicate, so I suspect the attributes were messed up\corrupted in some way that was preventing Exchange from replicating them. Now that the public folders were adjusted, and probably some others too, to have a custom replication schedule that wasn’t needed anymore I needed to clear out these values. So I wrote Fix-PFSchedule.ps1 to do this, plus a few other things.

The Get-PFInfo.ps1 script is the one I used to get Public Folder data, which writes it to the console and to a CSV file.


# This script will get item count and item size from every Public Folder the folder specified 
# Created by Jason Sherry |
# Created: 12/31/2012 | Last Updated: 1/1/2013
# Source:

#Exchange 2010 version, will not work on 2007
	[Parameter(Mandatory = $true)]
	[String] $PublicFolder

$computerName = $env:computerName

Function FixFileName ($FileName) {
	$FileName = $FileName.Replace('/', '_')
	$FileName = $FileName.Replace('\', '-')
	$FileName = $FileName.Replace(':', '_')
	$FileName = $FileName.Replace('*', '_')
	$FileName = $FileName.Replace('?', '_')
	$FileName = $FileName.Replace('"', '_')
	$FileName = $FileName.Replace('<', '_')
	$FileName = $FileName.Replace('>', '_')
	$FileName = $FileName.Replace('|', '_')
	Return $FileName

$OutputFile = FixFileName($PublicFolder)
$OutputFile = ".\" + $computerName + "-PF-Info " + $OutputFile + ".csv"
Write-Host "Getting all Public Folders under [$PublicFolder], saving data to [$OutputFile]" -ForegroundColor Cyan
$PFs = get-publicfolder $PublicFolder -ResultSize Unlimited -Recurse
Write-Host "`tFound " $PFs.Count -ForegroundColor Blue
Write-Host "Item `t MBs `t Path"
$TotalSize = 0
$TotalItemCount = 0
$PFs | ForEach {
	$PFStats = Get-PublicFolderStatistics $_.Identity
	$FolderSize = $PFStats.TotalItemSize.Value.ToMB()
	$FolderItemCount = $PFStats.ItemCount
	$TotalSize = $TotalSize  + $FolderSize
	$TotalItemCount = $TotalItemCount + $FolderItemCount
	Write-Host $PFStats.ItemCount `t $PFStats.TotalItemSize.Value.ToMB() `t $PFStats.FolderPath
	$PFStats | Select FolderPath, ItemCount, @{Expression={$_.TotalItemSize.Value.ToKB()};Label="Size (KB)"}, LastModificationTime
}| export-csv -NoTypeInformation $OutPutFile -Encoding unicode
Write-Host "Total Item Count: $TotalItemCount | Total Size: $TotalSize (MB)" -ForegroundColor Cyan


# This script will set the ReplicationSchedule for Public Folders, in an attempt to get Public Folders to replicate
# It is assumed that the Replicas have already been setup, but the folders aren't replicating

# Created by Jason Sherry |
# Created: 11/24/2012 | Last Updated: 1/1/2013
# Source:

	[Parameter(Mandatory = $true)]
	[String] $PublicFolder

$GetStats = $False
$Update = $False
$Server = "IZSRVEX01"
$LogFile = "Fix-PF.log"

$Text =  "Getting Public Folder: [$PublicFolder] and its children"
Write-Host $Text ; Add-Content $LogFile $Text

$PublicFolders = Get-PublicFolder $PublicFolder -ResultSize Unlimited -Recurse
$Text =  "Folder Count: " + $PublicFolders.Count
Write-Host $Text ; Add-Content $LogFile $Text
ForEach ($Pf in $PublicFolders) {
	$Text = "Processing " + $Pf.Identity
	Write-Host $Text ; Add-Content $LogFile $Text
	If ($PF.UseDatabaseReplicationSchedule -eq $False) {
		Set-PublicFolder $PF -UseDatabaseReplicationSchedule $False -ReplicationSchedule Always
		Set-PublicFolder $PF -UseDatabaseReplicationSchedule $True
		Write-Host "`t Schedule reset to default"
	If ($Update) { 
		Update-PublicFolder $PF -Server $Server
	If ($GetStats) {
	$PFStats = Get-PublicFolderStatistics $PF
		$Text =  "`tItems: " + $PFStats.ItemCount + " Size: " + $PFStats.TotalItemSize.Value.ToKB()
		Write-Host $Text -ForegroundColor "Blue"; Add-Content $LogFile $Text

		$Text =  "`tReplicas:" + $PF.Replicas + "`tUse Default:" + $PF.UseDatabaseReplicationSchedule + "`n`tSchedule:" + $PF.ReplicationSchedule
		Write-Host $Text ; Add-Content $LogFile $Text
		$Date = Get-Date
		Write-Host "Time: " $Date.ToShortDateString() " " $Date.ToShortTimeString()

About Jason Sherry

I am a ~30 year Exchange consultant and expert. I currently work for Commvault as a Solutions Specialist for Microsoft Infrastructure For more info see my resume at:
This entry was posted in Exchange, Script, Technical and tagged , , , . Bookmark the permalink.

1 Response to Script: Get-PFInfo.ps1, Fix-PFSchedule.ps1 & some PF replication troubleshooting info

  1. Pingback: Script: Get-PFInfo.ps1, Fix-PFSchedule.ps1 & some PF replication troubleshooting info | Jason (Izzy) Sherry’s Blog « JC’s Blog-O-Gibberish

Leave a Reply

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

You are commenting using your 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 )

Connecting to %s