Monitoring with PowerShell: Monitoring Outlook offline mode and OST Sizes, and active PSTS.

As some of you have noticed I haven’t really been blogging for the past 2 weeks. My father recently died and I had to take some me-time. I’m going to be getting back to blogging regularly again starting now 🙂

Todays blog I’m going to be showing how to monitor if outlook has been set to offline mode by the user, and if the OST size is nearing it’s maximum size, as a bonus I’m also giving you the option of alerting on active PST files. The offline mode is just a handy gizmo to notify users that they might’ve misclicked – It still happens to our users from time to time.

We have a lot of users that work in shared mailboxes. These shared mailboxes get added to the user via automapping. Automapping dumps all the information into a single users OST. The official maximum OST size is 100GB, so if you have 10 shared mailboxes of 10GB, the OST can get full and the user won’t be able to send or receive e-mails.

Monitoring offline mode

So this script uses my RunAsUser Module. This is because Outlook only runs in user mode and as such you need to run these commands as the user itself.

Install-module RunAsUser -Force
$ScriptBlock = {
    try {
        $outlook = new-object -comobject outlook.application
        $State = if ($outlook.session.offline) {"Outlook has been set to work offline mode." } else { "Healthy - Outlook is in online mode." }
        set-content "C:\programdata\Outlookmonitoring.txt" -value $State -force
    }
    catch {
        set-content "C:\programdata\Outlookmonitoring.txt" -Value  "Could not connect to outlook. " -Force
    }
}
Invoke-AsCurrentUser -UseWindowsPowerShell -NonElevatedSession -scriptblock $ScriptBlock
$Errorstate = get-content "C:\programdata\Outlookmonitoring.txt"

$Errorstate

Monitoring OST Sizes

So like I said before; the maximum size of a OST is 100GB, above that you’ll experience lots of performance loss so we want to keep it nice and small. Let’s say around 60GB. By using this monitoring method you can find exactly which OSTS are in use and how large they are.

Install-module RunAsUser -Force
$ScriptBlock = {
    try {
        $FileSizeAlert = 60GB
        $outlook = new-object -comobject outlook.application
        $OSTS = ($outlook.session.stores | where-object {$_.filepath -ne ""}).filepath
        $State = foreach ($OST in $OSTS) {
            $File = get-item $OST
            if($File.Length -gt $FileSizeAlert){ "$OST is larger than alert size" }
        }
        if(!$State){ $State = "Healthy - No Large OST found."}
        set-content "C:\programdata\OutlookOSTmonitoring.txt" -value $State -force
    }
    catch {
        set-content "C:\programdata\OutlookOSTmonitoring.txt" -Value  "Could not connect to outlook. " -Force
    }
}
Invoke-AsCurrentUser -UseWindowsPowerShell -NonElevatedSession -scriptblock $ScriptBlock
$Errorstate = get-content "C:\programdata\OutlookOSTmonitoring.txt"

$Errorstate

Finding actively used PST files

Of course we all want to avoid PST files as much as possible, they are prone to dataloss and just a pretty fragile format in general. To find if users have a PST actively mounted in Oulook you can use the following script:

Install-module RunAsUser -Force
$ScriptBlock = {
    try {
        $outlook = new-object -comobject outlook.application
        $PSTS = ($outlook.session.stores | where-object { $_.filepath -like "*pst" }).filepath
        if (!$PSTS) { $PSTS = "Healthy - No active PST found." }
        set-content "C:\programdata\OutlookPSTmonitoring.txt" -value $PSTS -force
    }
    catch {
        set-content "C:\programdata\OutlookPSTmonitoring.txt" -Value  "Could not connect to outlook. " -Force
    }
}
Invoke-AsCurrentUser -UseWindowsPowerShell -NonElevatedSession -scriptblock $ScriptBlock
$Errorstate = get-content "C:\programdata\OutlookPSTmonitoring.txt"

$Errorstate

And that’s all! As always, Happy PowerShelling

Recent Articles

The return of CyberDrain CTF

CyberDrain CTF returns! (and so do I!)

It’s been since september that I actually picked up a digital pen equivalent and wrote anything down. This was due to me being busy with life but also my side projects like CIPP. I’m trying to get back into the game of scripting and blogging about these scripts. There’s still so much to automate and so little time, right? ;)

Monitoring with PowerShell: Monitoring Acronis Backups

Intro

This is a monitoring script requested via Reddit, One of the reddit r/msp users wondered how they can monitor Acronis a little bit easier. I jumped on this because it happened pretty much at the same time that I was asked to speak at the Acronis CyberSummit so it kinda made sense to script this so I have something to demonstrate at my session there.

Monitoring with PowerShell: Monitoring VSS Snapshots

Intro

Wow! It’s been a while since I’ve blogged. I’ve just been so swamped with CIPP that I’ve just let the blogging go entirely. It’s a shame because I think out of all my hobbies it’s one I enjoy the most. It’s always nice helping others achieve their scripting target. I even got a couple of LinkedIn questions asking if I was done with blogging but I’m not. Writing always gives me some more piece of mind so I’ll try to catch up again. I know I’ve said that before but this time I’ll follow through. I’m sitting down right now and scheduling the release of 5 blogs in one go. No more whining and no more waiting.