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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
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