Last active
October 31, 2016 10:42
-
-
Save dfinke/715aa83d194ea3215906 to your computer and use it in GitHub Desktop.
Uses COM to Look at yesterdays messages for a particular outlook account. Reporting Date, Subject and # Of Attachments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$email = 'finked@hotmail.com' | |
$targetDate = (Get-Date).AddDays(-1).ToString("d") # yesterday | |
if(Get-Process outlook -ErrorAction Ignore) { | |
return "Please stop Outlook and re-run" | |
} | |
Write-Progress -Activity "Outlook" -Status "Connecting" | |
if($script:outlook -eq $null) { $script:outlook = new-object -com outlook.application } | |
$olFolderInbox = 6 | |
Write-Progress -Activity "Outlook" -Status "Connecting to target mailbox" | |
$ns = $outlook.GetNameSpace("MAPI") | |
$account = $ns.Folders | Where-Object {$PSItem.FolderPath -match $email} | |
$inbox = $account.Folders|?{$_.name -eq 'inbox'} | |
Write-Progress -Activity "Outlook" -Status "Getting messages for $($targetDate)" | |
($inbox.items.Restrict("[LastModificationTime] > '$($targetDate)'")) | | |
sort LastModificationTime -Descending| | |
ForEach { | |
[PSCustomObject][Ordered]@{ | |
Date = $_.LastModificationTime | |
Subject = $_.Subject | |
TotalAttachments=$_.Attachments.count | |
} | |
} | Out-GridView | |
$script:outlook.quit() | |
[void][System.Runtime.InteropServices.Marshal]::ReleaseComObject([System.__ComObject]$script:outlook) | |
$script:outlook=$null | |
ps outlook | kill |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment