2022-06-09 16:35:26 +02:00
|
|
|
|
<#
|
|
|
|
|
.SYNOPSIS
|
2022-10-12 15:12:38 +02:00
|
|
|
|
Checks Outlook's inbox
|
2022-06-09 16:35:26 +02:00
|
|
|
|
.DESCRIPTION
|
2022-10-12 15:12:38 +02:00
|
|
|
|
This PowerShell script checks the inbox of Outlook for new/unread mails.
|
2022-06-09 16:35:26 +02:00
|
|
|
|
.EXAMPLE
|
|
|
|
|
PS> ./check-outlook
|
|
|
|
|
.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 }
|
2022-10-12 15:12:38 +02:00
|
|
|
|
"⚠️ New mail '$($Mail.Subject)' from $($Mail.SenderName)."
|
2022-06-09 16:35:26 +02:00
|
|
|
|
$Unread++
|
|
|
|
|
}
|
2022-10-12 15:12:38 +02:00
|
|
|
|
if ($Unread -eq 0) { "✅ No new mails." }
|
2022-06-09 16:35:26 +02:00
|
|
|
|
exit 0 # success
|
|
|
|
|
} catch {
|
|
|
|
|
"Sorry: $($Error[0])"
|
|
|
|
|
exit 1
|
2022-10-12 15:12:38 +02:00
|
|
|
|
}
|