From 3f9ee0d0236e300598e7ee24c8b69aff90ec861e Mon Sep 17 00:00:00 2001 From: Markus Fleschutz Date: Wed, 12 Oct 2022 15:12:38 +0200 Subject: [PATCH] Update check-outlook.ps1 --- Scripts/check-outlook.ps1 | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/Scripts/check-outlook.ps1 b/Scripts/check-outlook.ps1 index d7f56068..6fc796cb 100755 --- a/Scripts/check-outlook.ps1 +++ b/Scripts/check-outlook.ps1 @@ -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 -} +} \ No newline at end of file