2023-07-29 10:34:04 +02:00
|
|
|
*check-outlook.ps1*
|
|
|
|
================
|
2022-11-17 19:46:02 +01:00
|
|
|
|
|
|
|
This PowerShell script checks the inbox of Outlook for new/unread mails.
|
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
Parameters
|
|
|
|
----------
|
2022-11-17 19:46:02 +01:00
|
|
|
```powershell
|
2023-07-29 10:15:44 +02:00
|
|
|
PS> ./check-outlook.ps1 [<CommonParameters>]
|
2022-11-17 19:46:02 +01:00
|
|
|
|
|
|
|
[<CommonParameters>]
|
|
|
|
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
|
|
|
|
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
|
|
|
|
```
|
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
Example
|
|
|
|
-------
|
2022-11-17 19:46:02 +01:00
|
|
|
```powershell
|
2023-08-06 21:36:33 +02:00
|
|
|
PS> ./check-outlook.ps1
|
|
|
|
✅ No new mails.
|
2022-11-17 19:46:02 +01:00
|
|
|
|
|
|
|
```
|
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
Notes
|
|
|
|
-----
|
2022-11-17 19:46:02 +01:00
|
|
|
Author: Markus Fleschutz | License: CC0
|
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
Related Links
|
|
|
|
-------------
|
2022-11-17 19:46:02 +01:00
|
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
Script Content
|
|
|
|
--------------
|
2022-11-17 20:05:34 +01:00
|
|
|
```powershell
|
2022-11-17 20:02:26 +01:00
|
|
|
<#
|
|
|
|
.SYNOPSIS
|
|
|
|
Checks Outlook's inbox
|
|
|
|
.DESCRIPTION
|
|
|
|
This PowerShell script checks the inbox of Outlook for new/unread mails.
|
|
|
|
.EXAMPLE
|
2023-08-06 21:36:33 +02:00
|
|
|
PS> ./check-outlook.ps1
|
|
|
|
✅ No new mails.
|
2022-11-17 20:02:26 +01:00
|
|
|
.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 {
|
|
|
|
"Sorry: $($Error[0])"
|
|
|
|
exit 1
|
|
|
|
}
|
2022-11-17 20:05:34 +01:00
|
|
|
```
|
2022-11-17 20:02:26 +01:00
|
|
|
|
2023-09-13 09:49:05 +02:00
|
|
|
*(generated by convert-ps2md.ps1 using the comment-based help of check-outlook.ps1 as of 09/13/2023 09:48:38)*
|