As well as Mailboxes and Archives, Public Folders are another place you may want to use EWS to enumerate Items to do some enhanced reporting. Building on the Enumerate script from the last two post, this post will cover how to modify this script to enable access Public Folder and Public Folder Items.
To change the Mailbox code we have to access public folders requires one big change in the Mailbox script we have the line
in the FolderIdFromPath function. To access a Public folder we need to change this to
And that's pretty much it apart from renaming the function to PublicFolderIdFromPath this is all you have to do. One thing you can't do with Public Folders vs what you can do with Mailboxs and Archive folders is do a DeepTraversal of all the folders in a folder hierarchy. For the basic enumeration script this isn't a big deal because all the searches are done at a shallow level.
Exchange 2013 up
For Exchange 2013,2016 and Exchange Online there is one other change you should make to this script which is to add the X-AnchorHeader and X-PublicFolderMailbox headers to ensure routing happens correctly as per https://msdn.microsoft.com/en-us/library/office/dn818490(v=exchg.150).aspx and https://msdn.microsoft.com/en-us/library/office/dn818491(v=exchg.150).aspx. It gets a little complicated here but because the Hierarchy and content maybe located in a different Public Folder Mailboxes you have to use 2 different discovery mechanisms both the EWS Managed API discover like
and a POX Autodiscover (plain old XML) method like
I've put a full copy of this enumerate script up on git hub https://github.com/gscales/Powershell-Scripts/blob/master/EnumerateItemsInPublicFolder.ps1
For one example of what you can do with it if we take the sample from the last post on ItemAge we can create an ItemAge script for public folder items. eg