How to create a report on PST files in your environment

Recently I’ve been working on an Exchange migration from an Exchange 2016 environment to Exchange Online. The company had a lot of PST archives on home directories which we could import as an Online Archive for the users. But there also were a lot of PST files on department File Shares that needed to be inventoried. This blog post describes how to create a report on those files.

Requirements of the report

The report should give the location of the PST, the time/date of the file, and the owner of the file. The time/date gives a good indication about the file in regards to whether it is being used or not (When it’s opened in Outlook, it will immediately change the timestamp to the current time and date). But the Owner is also a good point of information because that’s being changed to the user when opened from Outlook. With this information, you can consult the users and ask them if the PST needs to be imported to a shared mailbox.

The script

Below is the script. Edit the $locationstoscan variable with the paths (Drive letter or UNC) you want to scan in.

#Fill the locationstoscan variable with all locations that need to be scanned
$locationstoscan = "D:\Exports", "D:\Temp"
 
#Loop through the locations and add the PST information to the total variable
$total = foreach ($location in $locationstoscan) {
    write-host Processing $share -ForegroundColor Green
    $psts = Get-ChildItem -Recurse -Path $location -Filter *.pst -ErrorAction SilentlyContinue | Sort-Object Fullname
    foreach ($pst in $psts) {
        [PSCustomObject]@{
            Filename           = $pst.FullName
            "Size In Mb"       = [math]::Round($pst.Length / 1Mb, 2)
            "Last Access Time" = $pst.LastAccessTime            
            "Last Write by"    = (Get-Acl $pst.FullName).Owner        
            "Last Write Time"  = $pst.LastWriteTime
        }
    }
}
 
#Export all results to a pst.csv file in c:\temp sorted on FileName
$total | Sort-Object Filename | export-csv -NoTypeInformation -Delimiter ';' -Path D:\Temp\pst.csv

The output of the script

Below is an example how what the report will look like. I changed a few things in it because there were customer names in it 😉 The owner is a local account on my laptop, but running it on a fileserver will show it in a domainname\username format. If the original user doesn’t exist, it will show the SID.

Download the script(s) from GitHub here

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.