How to create a report on PST files in your environment

Recently I’m 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, time/date of the file, and the owner of the file. The time/date gives a good indication about the file in regards to 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 being 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 if needed.

The script

Below is the script, edit the $locationstoscan variable with the paths (Driveletter or UNC) you want to scan in.

#Set total variable to null
$total = @()

#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
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) {
        $csv = [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
        }
        $total += $csv
    }
}

#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 when you run it on a fileserver it 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.