Skip to content

Instantly share code, notes, and snippets.

@dfinke
Last active October 31, 2016 10:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dfinke/715aa83d194ea3215906 to your computer and use it in GitHub Desktop.
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
$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