1
votes

So I'm checking for an approach on a problem I have.

I have an e-mail from my school (Office 365) and I wanted to print the email subject of each email that's located in my inbox with PowerShell.

I already have found the method to lay a connection

$UserCredential = Get-Credential 
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://smtp.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
function Connect-O365 {
    $session365 = New-PSSession `
                    -ConfigurationName Microsoft.Exchange `
                    -ConnectionUri "https://smtp.office365.com/powershell-liveid/" `
                    -Credential $UserCredential
                    -Authentication Basic `
                    -AllowRedirection 
    Import-Module (Import-PSSession $session365 -AllowClobber) -Global
}

And have found the Get-Mailbox cmdlet.

The problem now however is that I haven't found any real examples or methods that continue to help me printing the email subjects.

I have done quite some research and didn't manage to find something like:

Get-Mailbox -Identity "user" |Select-MailBox * |Where-Object $_.MailBoxName = "Inbox"

Is this not possible or do I have to use another method?

1
Last time I checked you can only parse email subjects with Outlook or similar client, you can't gather enough from administration. You can get some data with Get-MessageTrackingLog, that one displays subjects of messages, but if you want all the mailbox, your best bet would be connecting with Outlook.Application (requires Office installed on local machine) and then parsing your inbox. - Vesper
Thank you very much for your answer Vesper, I will do some further research - Kahn Kah
You should use the EWS API for this (OR use the Search-mailbox er Get-MessageTrace cmdlet, but EWS is in my opinion better for this). For info about how to use EWS with Powershell you should look at the blog of fellow SO user Glen Scales (gsexdev.blogspot.nl), he has written a lot of good samples. Using the Outlook COM object isn't the best approach, it's slow and doesn't support automation in a proper fashion. - bluuf
Thanks bluuf, I'm gonna check that out - Kahn Kah

1 Answers

1
votes

If you have an Office365 subscription you could use the Office 365 api via their graph api endpoint

Since this is basically a REST endpoint you can use the Invoke-Webrequest or Invoke-RestMethod cmdlets.

Or more specificaly the Outlook api.

Both give you json back with you messages content like subject, to, from, and whatever.