-
-
Notifications
You must be signed in to change notification settings - Fork 547
Expand file tree
/
Copy pathcheck-outlook.ps1
More file actions
executable file
·31 lines (30 loc) · 836 Bytes
/
check-outlook.ps1
File metadata and controls
executable file
·31 lines (30 loc) · 836 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<#
.SYNOPSIS
Checks Outlook's inbox
.DESCRIPTION
This PowerShell script checks the inbox of Outlook for new/unread mails.
.EXAMPLE
PS> ./check-outlook.ps1
✅ No new mails.
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
try {
Add-Type -assembly "Microsoft.Office.Interop.Outlook"
$Outlook = New-Object -comobject Outlook.Application
$Namespace = $Outlook.GetNameSpace("MAPI")
$Inbox = $Namespace.GetDefaultFolder(6) # 6 = olFolderInbox
[int]$Unread = 0
foreach($Mail in $Inbox.Items) {
if ($Mail.Unread -eq $false) { continue }
"⚠️ New mail '$($Mail.Subject)' from $($Mail.SenderName)."
$Unread++
}
if ($Unread -eq 0) { "✅ No new mails." }
exit 0 # success
} catch {
"⚠️ ERROR: $($Error[0]) (at line $($_.InvocationInfo.ScriptLineNumber))"
exit 1
}