PowerShell/Docs/check-outlook.md

61 lines
1.4 KiB
Markdown
Raw Normal View History

2022-12-04 10:40:18 +01:00
## The *check-outlook.ps1* Script
2022-11-17 19:46:02 +01:00
This PowerShell script checks the inbox of Outlook for new/unread mails.
## Parameters
```powershell
check-outlook.ps1 [<CommonParameters>]
[<CommonParameters>]
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
```
## Example
```powershell
PS> ./check-outlook
```
## Notes
Author: Markus Fleschutz | License: CC0
## Related Links
https://github.com/fleschutz/PowerShell
2022-11-17 20:02:26 +01:00
## Source Code
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
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 }
"⚠️ 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
2022-11-17 19:46:02 +01:00
*Generated by convert-ps2md.ps1 using the comment-based help of check-outlook.ps1*