Export a list of all mail enabled public folders with their email address and path

First let me start off by saying, this is not a post to show off my powershell skills because let me tell you, they suck and I have no desire to improve them.

I ran into a slight problem at work this past month. We needed to provide a list of all of our Mail-Enabled Public Folder’s email address and location in order that we could migrate them to Google Groups/Users. As I searched the internet, I quickly found that this wasn’t an “easy” task in Exchange. I was in complete and utter shock that Exchange didn’t have some quick way of doing this. The only built in options I could find where to either get all Public Folders (Get-PublicFolder) with their locations or to get all Mail-Enabled Folders (Get-MailPublicFolder) with their email address and no location. This of course is problematic when you need all Public Folder’s email address + location.

I ended up combining a few powershell techniques I found across the internet to get the desired result. This little and simple powershell script will save a CSV with all of the Mail-Enabled Public Folders email address and location.

## export-mail-enabled-public-folders.ps1 ##
############################################

$resultsarray = @()

$mailpub = Get-MailPublicFolder -ResultSize unlimited
foreach ($folder in $mailpub) {
  $email      = $folder.primarysmtpaddress.local + "@" + $folder.primarysmtpaddress.domain
  $pubfolder  = Get-PublicFolder -Identity $folder.identity
  $folderpath = $pubfolder.parentpath + "\" + $pubfolder.name

  # Create a new object for the purpose of exporting as a CSV
  $pubObject = new-object PSObject
  $pubObject | add-member -membertype NoteProperty -name "Email" -Value $email
  $pubObject | add-member -membertype NoteProperty -name "FolderPath" -Value $folderpath


  # Append this iteration of our for loop to our results array.
  $resultsarray += $pubObject
}

# Finally we want export our results to a CSV:
$resultsarray | export-csv -Path $env:userprofile\Desktop\mail-enabled-public-folders.csv

Below is some example output:

#TYPE System.Management.Automation.PSCustomObject
"Email","FolderPath"
"[email protected]","\Company US\Global Systems\GS_request"
"[email protected]","\Company US\HR"
"[email protected]","\Company US\IT"
"[email protected]","\Company US\IT\Purchases"
"[email protected]","\Company US\Japan"
"[email protected]","\Company US\Japan\JPN-Sales"
"[email protected]","\Company US\Marketing"
"[email protected]","\Company US\Marketing\Webmaster"
"[email protected]","\Company US\Marketing\Webmaster\Blog Feedback"
"[email protected]","\Company US\Marketing\Webmaster\Domain Registration"
"[email protected]","\Company US\Marketing\Webmaster\Feedblitz signups"
"[email protected]","\Company US\Marketing\Webmaster\Sample Maps"
"[email protected]","\Company US\Marketing Calendar"
"[email protected]","\Company US\Product"
"[email protected]","\Company US\Product\Archive"
"R&[email protected]","\Company US\R&D"
"[email protected]","\Company US\R&D\Muse"
"[email protected]","\Company US\R&D\Muse\Bugs"
"[email protected]","\Company US\R&D\Muse\Handled items"
"[email protected]","\Company US\Sales Ops\resellerorder"
"[email protected]","\Company US\Sales Ops\resellerorder\Reseller Orders Completed"
"[email protected]","\Company US\Sales Ops\resellerorder\Time Off Schedule"
"[email protected]","\Company US\Sales\Sales Calendar"

Loading Comments...