Obtain the size of your Public Folder database using PowerShell

If you’re looking to find out the size of your Public Folder database you’ll be out of luck in the Exchange Management Console. Looking at the Properties (Under Server Config > Mailbox) will tell you the path, last backup and modified dates, but nothing about size. Of course using the path you can look at the disk directly and obtain information on the size the database consumes from there.

Another GUI option is from Outlook. Right-click on the public folder and select “Data File Properties”, in the window that pops up hit “Folder Size”, after a bit (or a lot!) of thinking the total folder size will be returned.

The article at http://technet.microsoft.com/en-us/library/bb123996(v=exchg.80).aspx states “A larger maximum database size is possible when continuous replication is used. We recommend the following maximum database sizes for Exchange 2007: Databases hosted on a Mailbox server with continuous replication and Gigabit Ethernet: 200 GB”. So I think it would be useful to tracking Public Folder growth over time (we all know how management loves a good graph) in order to avoid going over the 200Gb recommended maximum.

So what if you want to script this check? I couldn’t find any steps online on how to get a script to return the results, which is why I’ve included it here.

The command to work with is Get-PublicFolderStatistics. This is a powerful command which returns a huge amount of data. The columns returned by default are: Name, ItemCount and LastAccessTime, and each folder within your entire public folder infrastructure will be enumerated.

The main problem I found with the data returned is that the sizes are not numeric values, smaller folder sizes will be appended with a “B” for Bytes, whereas larger (+1Mb) folders will be appended with “KB” for KiloBytes. The script below makes allowances for these and strips the letters from the numbers (by converting to a string), and in the case of data in kilobytes multiplying the output by 1024 so all values are in bytes.

You could expand the IF statement if any folders are over 1Gb in size, and warrant an “Mb” appended, however I would hope this situation doesn’t occur!

Finally it rounds up to Gb with 2 decimal points for ease of display.

$Server = 'servername'
$Folders = Get-PublicFolderStatistics -server $Server | Where {$_.TotalItemSize -ne "0B"}  
$TotalBytes = 0
ForEach ($Item in $Folders) {
     $TotalItemSize = $Item.TotalItemSize
     $TotalItemSize = [string]$TotalItemSize
     IF ( ($TotalItemSize.contains('KB')) ) {
          $TotalItemSize = $TotalItemSize -Replace ('KB','')
          $TotalItemSize = [int]$TotalItemSize * 1024
     $TotalItemSize = $TotalItemSize -Replace ('B','')
     $TotalBytes = [long]$TotalItemSize + [long]$TotalBytes
[math]::round($TotalBytes/1Gb, 2)
Posted in Guides Tagged with: , , ,
2 comments on “Obtain the size of your Public Folder database using PowerShell
  1. Lee Cordero says:

    Hi Tom, thank you for your post.

    Do you have the same script for exchange 2010?
    I tried in Ex2010 and doesn’t work

    I received some errors like:
    Cannot convert value “119.9 (122,820 bytes)” to type “System.Int32”. Error: “Input string was not in a correct format.”
    At C:\temp\publicfoldersize.ps1:9 char:47
    + $TotalItemSize = [int]$TotalItemSize <<<< * 1024
    + CategoryInfo : NotSpecified: (:) [], RuntimeException
    + FullyQualifiedErrorId : RuntimeException

    Cannot convert value "119.9 (122,820 ytes)" to type "System.Int64". Error: "Input string was not in a correct format."
    At C:\temp\publicfoldersize.ps1:12 char:40
    + $TotalBytes = [long]$TotalItemSize <<<< + [long]$TotalBytes
    + CategoryInfo : NotSpecified: (:) [], RuntimeException
    + FullyQualifiedErrorId : RuntimeException

  2. tomanderson says:

    Without being able to test this myself, from your output it would appear you need to change line 8 to

    $TotalItemSize = $TotalItemSize -Replace (‘KBytes’,”)

    Let me know how you get on.



Leave a Reply

Your email address will not be published. Required fields are marked *