You may use the script below in the Exchange Management Shell to list all public folders and their primary email address in Microsoft Exchange Server 2007.
<#
.SYNOPSIS
Query all of the Microsoft Exchange Server 2007 public folders, provide their primary email address and write the output to a file.
.DESCRIPTION
Automate the output of the email addresses associated with the Microsoft Exchange Server 2007 public folders.
.EXAMPLE
Get-Mailpublicfolder | Format-List alias, emailaddresses | Out-File -filepath C:\Users\User01\Desktop\email.txt
.AUTHOR
Written by Noel Enrique Alvarez on Thursday, January 28, 2016.
#>
#Request the name of the file.
$File = Read-Host “What will be the name of the file?”
#Query the Microsoft Exchange Server 2007 public folders and provide the results in a text file
Get-Mailpublicfolder | Format-List alias, emailaddresses | Out-File -filepath <<<INSERT PATH>>>\$File