Last active
May 22, 2020 23:54
-
-
Save cdhunt/f03c6f33ed50323ab6ac to your computer and use it in GitHub Desktop.
Browse your email from PowerShell like a folder
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
Import-Module Simplex | |
New-PSDrive mail -psprovider simplex -root "C:\Temp\outlookprov.ps1" | |
cd mail:\Inbox |
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" | Out-Null | |
$olFolders = "Microsoft.Office.Interop.Outlook.olDefaultFolders" -as [type] | |
$outlook = new-object -comobject outlook.application | |
$namespace = $outlook.GetNameSpace("MAPI") | |
$inbox = $namespace.getDefaultFolder($olFolders::olFolderInBox) | |
root { | |
script Inbox { | |
$inbox.Items | |
} | |
$inbox.Folders | foreach-object { | |
$subFolder = $_ | |
$content = Split-Path $subFolder.folderpath -Leaf | |
script "$content" { | |
$subFolder.Items | |
}.GetNewClosure(); | |
} | |
} | |
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
function Send-MailReply | |
{ | |
[CmdletBinding()] | |
Param | |
( | |
# Param1 help description | |
[Parameter(Mandatory=$true, | |
ValueFromPipeline=$true, | |
Position=1)] | |
$InputObject, | |
# Param2 help description | |
[Parameter(Mandatory=$true, | |
Position=0)] | |
[string] | |
$To | |
) | |
Process | |
{ | |
$newMessage = $InputObject.Reply() | |
$newMessage.To = $To | |
$newMessage.Send() | |
} | |
} | |
function Send-MailForward | |
{ | |
[CmdletBinding()] | |
Param | |
( | |
# Param1 help description | |
[Parameter(Mandatory=$true, | |
ValueFromPipeline=$true, | |
Position=1)] | |
$InputObject, | |
# Param2 help description | |
[Parameter(Mandatory=$true, | |
Position=0)] | |
[string] | |
$To | |
) | |
Process | |
{ | |
$newMessage = $InputObject.Forward() | |
$newMessage.To = $To | |
$newMessage.Send() | |
} | |
} | |
# Example | |
PS mail:\Inbox> ls | select -first 1 | Send-MailForward [email protected] |
Added example Reply and Forward functions.
Started a full repo: https://github.com/cdhunt/OutlookCLI
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The child of Get Outlook Inbox and Simplex.