Getting Public Folder Statistics Report in O365/Exchange Online
In this case, the customer was looking for a way to get the following information from the Public Folders in EXO - this was basically his "wish list" of information that he wanted to get:
- Folder Display name
- Folder Path
- Owner
- Item Count
- Last Access Time
- Last Modification Time
- Total Item Size
- Creation Time
- If it is mail enabled or not
- email address - if it is mail enabled
They were able to get this information when the folders were in on-premises Exchange, but have not been able to find a way to get this since they were migrated to O365. They wanted the information to use it to clean and remove thousands of unused folders but didn't know a way to get the data.
I found a script at https://gallery.technet.microsoft.com/office/Snapshot-report-of-Public-21235573 that was designed to get Public Folder data from Exchange 2010 and returned most of the customer's desired info.
It gets everything except for the Last Access info, which is not available in Exchange Online that I can find.
I'm supplying the script content as text here, and it can then be copied/paste it into a .ps1 file on the machine you intend to run it on, and it will be trusted, as the .ps1 file is seen as having been created on that machine, and not on some foreign machine.
From the original, I had to tweak the syntax to get the PrimarySmtpAddress and to get the list of owners, which I could only retrieve Display Names for. # This Sample Code is provided for the purpose of illustration only and is not intended to be used in a production environment. # THIS SAMPLE CODE AND ANY RELATED INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, # INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. # We grant You a nonexclusive, royalty-free right to use and modify the Sample Code and to reproduce and distribute the object # code form of the Sample Code, provided that You agree: (i) to not use Our name, logo, or trademarks to market # Your software product in which the Sample Code is embedded; (ii) to include a valid copyright notice on Your software product # in which the Sample Code is embedded; and (iii) to indemnify, hold harmless, and defend Us and Our suppliers from and against # any claims or lawsuits, including attorneys’ fees, that arise or result from the use or distribution of the Sample Code. Write-Progress -Activity "Finding Public Folders" -Status "running get-publicfolders -recurse" $folders = get-publicfolder -recurse -resultsize unlimited $arFolderData = @() $totalfolders = $folders.count $i = 1 foreach ($folder in $folders) { $statusstring = "$i of $totalfolders" write-Progress -Activity "Gathering Public Folder Information" -Status $statusstring -PercentComplete ($i/$totalfolders*100) $folderstats = get-publicfolderstatistics $folder.identity $folderdata = new-object Object $folderdata | add-member -type NoteProperty -name FolderName $folder.name $folderdata | add-member -type NoteProperty -name FolderPath $folder.identity $folderdata | add-member -type NoteProperty -name LastAccessed $folderstats.LastAccessTime $folderdata | add-member -type NoteProperty -name LastModified $folderstats.LastModificationTime $folderdata | add-member -type NoteProperty -name Created $folderstats.CreationTime $folderdata | add-member -type NoteProperty -name ItemCount $folderstats.ItemCount $folderdata | add-member -type NoteProperty -name Size $folderstats.TotalItemSize $folderdata | Add-Member -type NoteProperty -Name Mailenabled $folder.mailenabled if ($folder.mailenabled) { #since there is no guarentee that a public folder has a unique name we need to compare the PF's entry ID to the recipient objects external email address $entryid = $folder.entryid.tostring().substring(76,12) # $primaryemail = (get-recipient -filter "recipienttype -eq 'PublicFolder'" -resultsize unlimited) | where {$_.externalemailaddress -like "*$entryid"}).primarysmtpaddress $primaryemail = (get-recipient $folder.mailrecipientguid.tostring()).primarysmtpaddress $folderdata | add-member -type NoteProperty -name PrimaryEmailAddress $primaryemail } else { $folderdata | add-member -type NoteProperty -name PrimaryEmailAddress "Not Mail Enabled" } if ($folderstats.ownercount -gt 0) { $owners = get-publicfolderclientpermission $folder.identity | where {$_.accessrights -like "*owner*"} $ownerstr = "" foreach ($owner in $owners) { $ownerstr += $owner.user.displayname + "," } } else { $ownerstr = "" } $folderdata | add-member -type NoteProperty -name Owners $ownerstr $arFolderData += $folderdata $i++ } $arFolderData | export-csv -path PublicFolderData.csv -notypeinformation