PowerShell Script for counting elements in a PST file

Sun, Apr 19, 2020 2-minute read

PowerCountPST is a PowerShell Script lets you count the number of elements found in an Outlook PST file.

History

At work, we recently had a migration of our archiving solution (Easy for Exchange to Exchange Online Archives. Among the many steps such a migration requires, the most important one is to verify that all old emails -which had been exported- are complete. Trust me, these export tools provided by your archiving solution might not be as reliable as you’d think.

I was, therefore, looking for an efficient way to process all my 2000 PST files to see if they are accessible and complete. Considering the sheer amount of mailboxes a manual process using VBA code or scanpst.exe wouldn’t have been doable. Hence, I looked for a scripted solution and ultimately found this. While at first sight it looked promising, I soon enough noticed that this script had some serious limitations. This script only searches sub-sub folders if any PST files had any further subfolders within this file structure it would simply omit those. Another downside is, that it doesn’t unmount a PST file again. If you apply this script to a bunch of PST files you will soon enough see how both the script and outlook fail to process the files.

So I set out to create a solution called 🧮 PowerShell PowerCountPST. PowerCountPST is a PowerShell Script lets you count the number of elements found in an Outlook PST file. There are no limitations in terms of size and it’s blazingly fast. Unlike other solutions, PowerCountPST searches recursively, so no matter how your files PST files are structured, it will always yield back the accurate amount. Once it’s done it will unmount the PST file again, which makes it perfect to run in batches. PowerCountPST can be found on GitHub.

Usage

Run the script in a PowerShell command prompt and provide a PST file as a parameter:

1
.\PowerCountPsT.ps1 -pst C:\Temp\outlook.pst

Depending On the provided PST file, the output might look something like this:

1
2
3
4
5
6
7
8
9
Folder: \\test contains 3 items
Folder: \\test\Deleted Items contains 0 items
C:\Temp\outlook.pst
Total Items: 3
PSPath
------
Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Outlook.Application
0
3

I hope my script is also useful for your migration projects.