mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-11-22 07:53:21 +01:00
69 lines
1.5 KiB
Markdown
69 lines
1.5 KiB
Markdown
Script: *check-outlook.ps1*
|
|
========================
|
|
|
|
This PowerShell script checks the inbox of Outlook for new/unread mails.
|
|
|
|
Parameters
|
|
----------
|
|
```powershell
|
|
PS> ./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.ps1
|
|
✅ No new mails.
|
|
|
|
```
|
|
|
|
Notes
|
|
-----
|
|
Author: Markus Fleschutz | License: CC0
|
|
|
|
Related Links
|
|
-------------
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
Script Content
|
|
--------------
|
|
```powershell
|
|
<#
|
|
.SYNOPSIS
|
|
Checks Outlook's inbox
|
|
.DESCRIPTION
|
|
This PowerShell script checks the inbox of Outlook for new/unread mails.
|
|
.EXAMPLE
|
|
PS> ./check-outlook.ps1
|
|
✅ No new mails.
|
|
.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
|
|
}
|
|
```
|
|
|
|
*(generated by convert-ps2md.ps1 using the comment-based help of check-outlook.ps1 as of 08/15/2024 09:50:46)*
|