The more I work with PowerShell the more impressed I am with how useful of a tool it is to manage Exchange. In this blog I want to illustrate how easy it is to pull Public Folder data from your Exchange environment and export that data into a HTML format.  I think in every environment I have ever worked in or supported, Public Folders have grown out of control. This causes organizations to have to back up and replicate old and irrelevant data. Most administrators ignore cleaning up Public Folder because it is a headache to determine which Public Folders are still needed and which Public Folders can be removed. I have put together a PowerShell script that will comb all the Public Folders in your environment and report back some key attributes to help administrators keep a close eye on Public Folder size, date modified and date created. In a future post I will provided some successful steps I have used in the past to cleanup Public Folders but, for now we will look at getting information from Public Folders.

There are four tables created with this script and I will discuss each table. Another cool feature is each column is sortable to easily determine size or sort by name.

Note: To be able to use the sortable feature you will need to download the JS script form this website, http://www.kryogenix.org/code/browser/sorttable/.

Note: Some of these reports will only work with Exchange 2007 Public Folders. The first table shows the date and time when the script was run.

pf1

The second table shows Public Folder statistics. The script will filter the folders by the last time they were modified. In this example, we used the date 1/1/2008 as our reference point. Any Public Folders that were last modified before 1/1/2008 will be placed in the Over the last modified date table.  In this table we are sorting on the Total Item Size column.

pf2

The third table shows Public Folder statistics. Any Public Folders that where last modified after 1/1/2008 will be placed in the Under the last modified date table.  In this table we are sorting on the Total Item Size column.

pf3

The last table will show Public Folder information. This table will work with any version of Exchange. Here we are sorting on the Issue Warning Quota column.

pf4

This script will help you inventory your Public Folder data to help you remove stale data saving backup cycles and recovering storage space.  You can see more details about this script in the accompanying blog post here.

Download the complete PS1 here:  publicFolderDataToHTML.ps1 (2.24 kb)

The areas highlighted in red are the attributes which can be changed.

C:reports.htm – Is the location where the file will be created. You can change the file location to anywhere you want to just be aware that you need to make the change in the code in a multitude of locations.

c:sorttable.js – Change the location of the js script that you downloaded

$server – Enter the name of the Public Folder you want to sort against

$folder = enter the root folder name where you want the script to start at. The script will start at the root folder and look at any subfolders

1/1/2000 12:00:00 AM – You will want to change this date for your environment. Changing the data will change which table a Public Folder will be placed in.

Copy the code from the box below and save it as a PS1 file.

Get-Date | Select-Object Date | convertTo-HTML -head $a -Title "Public Folder Access" | Out-File c:report.htm

$server = "mailbox server name"

$folder = "HR"

$a= "<script src=c:sorttable.js type=text/javascript></script>"

$a = $a + "<style>"

$a = $a + "BODY{background-color:gray;}"

$a = $a + "TABLE.sortable thead {border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"

$a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:yellow}"

$a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:white}"

$a = $a + "</style>"

Get-PublicFolderStatistics -Server $server| Select-Object admindisplayname, creationtime, Lastmodificationtime, itemcount, totalitemsize, servername | where-object {$_.Lastmodificationtime -lt "1/1/2000 12:00:00 AM"} | convertTo-HTML  -Body "<H2>Over the last modified date</H2>"   |  Out-File c:report.htm -append

Get-PublicFolderStatistics -Server $server| Select-Object admindisplayname, creationtime, Lastmodificationtime, itemcount, totalitemsize, servername | where-object {$_.Lastmodificationtime -gt "1/1/2000 12:00:00 AM"} | convertTo-HTML  -Body "<H2>Under the last modified date</H2>" |  Out-File c:report.htm -append

Get-PublicFolder -Recurse -Server $server -Identity $folder | Select-Object Name, MailEnabled, HasSubFolders, IssueWarningQuota, MaxItemSize  | convertTo-HTML -head $a -Title "Public Folder Access" -Body "<H2>Public Folder Information</H2>" |  Out-File c:report.htm -append

(Get-Content C:report.htm) | Foreach-Object {$_ -replace "<table>", "<table class =sortable>"} | Set-Content C:report.htm

(Get-Content C:report.htm) | Foreach-Object {if($_ -like "*TotalItemSize*"){$_ -replace "t</th><th>", "t</th><th>"} else{$_}} | Set-Content C:report.htm

(Get-Content C:report.htm) | Foreach-Object {if($_ -like "*ItemCount*"){$_ -replace "ModificationTime</th><th>", "ModificationTime</th><th>"} else{$_}} | Set-Content C:report.htm

(Get-Content C:report.htm) | Foreach-Object {if($_ -like "*TotalItemSize*"){$_ -replace "count</th><th>", "count</th><th>"} else{$_}} | Set-Content C:report.htm

Happy Exchanging!!!!