Feeling pretty good about yourself you come into the office and sit down to get some work done. After all, someone has to retrieve that Amulet of Yendor so it might as well be you, right? Unfortunately it doesn’t look like today will be your day. The warnings are piling up that your mail queue is getting rather large and some users have been asking where their daily messages in their public folders are. Taking a peek at the queue you see a large and growing number of emails in your Unreachable Domain queue. But your public folder database looks like it is mounted OK. Not cool.
What broke?
This is a fairly common scenario I’ve run into after migrating off of Exchange 2003. Your public folders migrated over successfully and mail had been flowing for a while but as soon as you took down the 2003 server the mail starts queuing up for your mail enabled public folders. Or maybe you went in and started doing some manual cleanup with ADSI Edit. Sometimes even just the uninstall of Exchange 2003 has some unexpected side effects. You remembered to do a backup of your AD prior to that major change, right? There’s a good chance that your public folder hierarchy is missing.
Great, so can we fix this?
The good news is that there is a road to recovery. Let’s check on things first, is your public folder hierarchy actually missing? Pop open the good old Exchange Management Shell and let’s check on a few things.
Import-Module ActiveDirectory $SearchPath = "CN=Folder Hierarchies,CN=Exchange Administrative Group (FYDIBOHF23SPDLT),CN=Administrative Groups," + (Get-OrganizationConfig).DistinguishedName Get-ADObject -SearchBase $SearchPath -SearchScope OneLevel -Filter {CN -eq "Public Folders"}
Hopefully you will get a result such as below.
DistinguishedName Name ObjectClass ObjectGUID
—————– —- ———– ———-
CN=Public Folders,CN=Folde… Public Folders msExchPFTree f6a3cbd4-10e5-452d-9abe-44…
If you get a directory object not found then your public folder hierarchy is missing and we’ll have to recreate it. That’s step one on our way to saving the day. Let’s step back one further and make sure about whether our Folder Hierarchies container is there.
$SearchPath = "CN=Exchange Administrative Group (FYDIBOHF23SPDLT),CN=Administrative Groups," + (Get-OrganizationConfig).DistinguishedName Get-ADObject -SearchBase $SearchPath -SearchScope OneLevel -Filter {CN -eq "Folder Hierarchies"}
If you get no results then that is missing as well. If you do then at least our container is there and we just need to create the hierarchy. Here’s the bit of PowerShell code that will fix up the missing public folders hierarchy.
<# .SYNOPSIS Recreates your public folders hierarchy .DESCRIPTION Checks your AD for whether the Folder Hierarchies container exists and the Public Folders hierarchy. If one does not exist then it is created. #> Import-Module ActiveDirectory # Build path to the container $SearchPath = "CN=Exchange Administrative Group (FYDIBOHF23SPDLT),CN=Administrative Groups," + (Get-OrganizationConfig).DistinguishedName $PFContainer = Get-ADObject -SearchBase $SearchPath -SearchScope OneLevel -Filter {CN -eq "Folder Hierarchies"} # If it does not exist then create the container if(!$PFContainer) { New-ADObject -Name "Folder Hierarchies" -Type msExchPublicfolderTreeContainer -Path $SearchPath Write-Host "Folder Hierarchies container created." } else { Write-Host "Folder Hierarchies container exists already." -ForeGroundColor Yellow } # Build path for the public folder tree $SearchPath = "CN=Folder Hierarchies,CN=Exchange Administrative Group (FYDIBOHF23SPDLT),CN=Administrative Groups," + (Get-OrganizationConfig).DistinguishedName $PFHierarchy = Get-ADObject -SearchBase $SearchPath -SearchScope OneLevel -Filter {CN -eq "Public Folders"} # If it does not exist then create it if(!$PFHierarchy) { New-ADObject -Name "Public Folders" -Type msExchPFTree -Path $SearchPath -OtherAttributes @{msExchPFTreeType="1"} Write-Host "Public Folders hierarchy created." } else { Write-Host "Public Folders hierarchy already exists." -ForeGroundColor Yellow } # Set to our PF hierarchy DN $PFHierarchy = "CN=Public Folders," + $SearchPath # DN for our databases $SearchPath = "CN=Databases,CN=Exchange Administrative Group (FYDIBOHF23SPDLT),CN=Administrative Groups," + (Get-OrganizationConfig).DistinguishedName $PFDatabases = Get-ADObject -SearchBase $SearchPath -SearchScope OneLevel -Filter {objectClass -eq "msExchPublicMDB"} # Grab all of the public folder databases and loop through them if($PFDatabases) { foreach($PFDatabase in $PFDatabases) { $PFDatabase.msExchOwningPFTree = $PFHierarchy Set-ADObject -Instance $PFDatabase Write-Host "Fixed database $($PFDatabase.Name)" } } # Or if no public folder databases exist you have further problems ... else { Write-Host "No Public Folder Databases found." -ForeGroundColor Yellow }
But you’ll find that your work is not quite done yet. Your public folders are missing their homeMDB. Or this could have been your problem all along without any need to recreate the public folder hierarchy. You can verify this as the problem with this quick search:
$PFPath = "CN=Public Folders,CN=Folder Hierarchies,CN=Exchange Administrative Group (FYDIBOHF23SPDLT),CN=Administrative Groups," + (Get-OrganizationConfig).DistinguishedName $SearchBase = "CN=Microsoft Exchange System Objects," + (Get-ADRootDSE).rootDomainNamingContext Get-ADObject -SearchBase $SearchBase -SearchScope OneLevel -Filter { (homeMDB -notlike "*") -and (ObjectClass -eq "publicFolder")}
If you don’t see anything then you know that your mail enabled public folders are fine. But most likely you’ll get a few results. To quickly fix those up run through this script.
<# .SYNOPSIS Fix any missing homeMDB attributes on public folders. .DESCRIPTION The script runs an LDAP search for all mail enabled public folder objects and sets the homeMDB attribute to the LDAP path to your public folder hierarchy. .NOTES The script needs to be run in all domains requiring the fix. #> Import-Module ActiveDirectory # Build the DN to the public folders hierarchy $PFPath = "CN=Public Folders,CN=Folder Hierarchies,CN=Exchange Administrative Group (FYDIBOHF23SPDLT),CN=Administrative Groups," + (Get-OrganizationConfig).DistinguishedName # Build the DN to the public folder objects $SearchBase = "CN=Microsoft Exchange System Objects," + (Get-ADRootDSE).rootDomainNamingContext # Search for all PFs with a blank homeMDB $TargetPFs = Get-ADObject -SearchBase $SearchBase -SearchScope OneLevel -Filter { (homeMDB -notlike "*") -and (ObjectClass -eq "publicFolder")} # Fix all of the public folders if($TargetPFs) { foreach($TargetPF in $TargetPFs) { Write-Host "Fixing $($TargetPF.Name)" $TargetPF.homeMDB = $PFPath Set-ADObject -Instance $TargetPF } } # Good news (maybe), no public folders that require fixing else { Write-Host "No public folders missing homemdb." }
Fantastic, are we done yet?
Nearly! Just give the mail queues a kick and you should see the emails quickly flushing out into your public folder databases. Now you can get back to your day of NetHack knowing that all is well with the world once again.