Last active
October 30, 2018 09:29
-
-
Save rdapaz/79b3d0fb7c38d0191abfb16bcb477f97 to your computer and use it in GitHub Desktop.
Go through emails
This file contains hidden or 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
Add-Type -assembly "Microsoft.Office.Interop.Outlook" | |
$Outlook = New-Object -comobject Outlook.Application | |
$namespace = $Outlook.GetNameSpace("MAPI") | |
# Do stuff | |
# Folders.Item(2).Folders.Item(2) is Inbox on the second email account | |
$sntItems = $namespace.Folders.Item(3).Folders.Item(4) | |
$f = $sntItems | |
$outItems = New-Object System.Collections.Generic.List[System.Object] | |
$f.Items | ? { | |
$_.SentOn -gt (get-date).AddDays(-30) | |
} | % { | |
$obj = New-Object -typename psObject -Property @{Date = $_.SentOn; To =$_.To; Subject = $_.Subject; Body = $_.Body; Status = 'Sent';} | |
$outItems.Add($obj) | |
} | |
$inbox = $namespace.Folders.Item(3).Folders.Item(2) | |
$f = $inbox | |
$f.Items | ? { | |
$_.SentOn -gt (get-date).AddDays(-30) | |
} | % { | |
$obj = New-Object -typename psObject -Property @{Date = $_.ReceivedTime; To =$_.SenderName; Subject = $_.Subject; Body = $_.Body; Status = 'Received';} | |
$outItems.Add($obj) | |
} | |
#$outItems | Export-Csv "C:\users\rdapaz.DESKTOP-QSI65RE\Desktop\emails.csv" | |
$outItems | convertto-json -depth 100 | out-file "C:\users\rdapaz.DESKTOP-QSI65RE\Desktop\emails.json" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment