mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-03-25 21:46:43 +01:00
Update check-outlook.ps1
This commit is contained in:
parent
e0b603f1b6
commit
3f9ee0d023
@ -1,8 +1,8 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Checks Outlook's Inbox
|
||||
Checks Outlook's inbox
|
||||
.DESCRIPTION
|
||||
This PowerShell script checks the inbox of Outlook for new mails.
|
||||
This PowerShell script checks the inbox of Outlook for new/unread mails.
|
||||
.EXAMPLE
|
||||
PS> ./check-outlook
|
||||
.LINK
|
||||
@ -17,23 +17,14 @@ try {
|
||||
$Namespace = $Outlook.GetNameSpace("MAPI")
|
||||
$Inbox = $Namespace.GetDefaultFolder(6) # 6 = olFolderInbox
|
||||
[int]$Unread = 0
|
||||
$Sender = ""
|
||||
[switch]$SameSender = $true
|
||||
foreach($Mail in $Inbox.Items) {
|
||||
if ($Mail.Unread -eq $false) { continue }
|
||||
"⚠️ New mail '$($Mail.Subject)' from $($Mail.SenderName)."
|
||||
$Unread++
|
||||
if ("$Sender" -eq "") { $Sender = $Mail.SenderName
|
||||
} elseif ("$Sender" -ne "$($Mail.SenderName)") { $SameSender = $false }
|
||||
$Subject = $Mail.Subject
|
||||
}
|
||||
if ($Unread -eq 0) { $Reply = "No new mails."
|
||||
} elseif ($Unread -eq 1) { $Reply = "One new mail from $Sender regarding $Subject."
|
||||
} elseif ($SameSender) { $Reply = "$Unread new mails from $Sender."
|
||||
} else { $Reply = "$Unread new mails."
|
||||
}
|
||||
"$Reply"
|
||||
if ($Unread -eq 0) { "✅ No new mails." }
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"Sorry: $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user