MS O365 Exchange email input to PowerShell output


Can we monitor a Microsoft Exchange server in the cloud using Office365 and process the emails with a PowerShell output script?


This article will demonstrate how you can process unread emails from an MS O365 Exchange server and output the email as a text file using PowerShell.

File Processor:
Input: Email
Output: Script


Let us assume that you have basic knowledge of the File Processor, we will only configure Input and Output.


  1. Go to the Input and select Input Type: Email.
  2. In the Connection tab select for Type: MS Echange.
  3. Fill in the Login information
    Password: yoursecret

    Exchange Web Services (EWS) URL:
  4. In the Options tab, select the Folder, e.g. Inbox by clicking the Browse button. This is the email folder with the emails that you want to process.
    Data to return: Only the e-mail.


  1. Go to the Output and select Output Type: Script.
  2. Click the Edit-button, behind the Script label to open the Script Editor.
  3. Set the Script language to PowerShell.
  4. For the script use the code below: It will take the email and write the contents to a unique file.
    Change the path K:\Winking\FileProcessor\out to your desired location.
function ProcessData($lg, $data, $parameters) {
    # add PowerShell code here 
		$data | Out-File -FilePath "K:\Winking\FileProcessor\out\data-$(Get-Date -Format FileDateTime).txt"

    $boolResult = $true; # boolean with result to return
    return $boolResult;


  1. At the Success-Post-Actions tab, select Type: Method and choose Method: Mark as read.

When finishing processing an unread email it will mark the email as read. File Processor only processes unread emails.


At your configured folder K:\Winking\FileProcessor\out\ you should see several files e.g. data-20220303T1015169251.txt with content:

DataContents     :
DateTimeCreated  :
DateTimeReceived :
DataID           :
Worker           :
From             :
To               :
Bcc              :
CC               :
DateTimeSent     :
Subject          :
TextBody         :
HtmlBody         :
ConfigData       :

See also