Exporting Mails from Exchange Online mailbox to CSV file with Powershell

export exchange online to csv

First article about export from Outlook to CSV using Outlook API can be found here.

In this article we have a Powershell program which exports mails from list of folders in mailbox located in Exchange Online to single CSV file.

Program utilize functionality provided by Microsoft Graph and does not need MS Outlook to be installed on a computer where you run the program

Program process folders specified in foldersToExport parameter. If they have any subfolders – subfolders are also processed.

Paramaters:

pathToSaveFiles – path to create CSV file, if not specified will take current script execution path.
UPN – User Principal Name. Usually in a form of email of user which mailbox we going to process.
maxRecordToProcessForEachFolder – max records to process for each folder. If you want “no limit” put some huge value there.. like 50000000.
foldersToExport – second level folders to start export from.

Program output emails to <yyyyMMdd-HHmmss>_<UPN>_exportedGraph.csv – file created in the folder specified by pathToSaveFiles parameter

Example usage from powershell: .\exchangeOnline2CSV.ps1 -upn “user@domain.com” -maxRecordToProcessForEachFolder 10 -foldersToExport “inbox”,”sent items”

Program is created as Proof Of Concept and provided as is, with absolutely no warranty expressed or implied. Any use is at your own risk.

You can download program from this Github repository.

Leave a Reply

Your email address will not be published.