PowerShell: Add MSG file metadata to a SharePoint list

Table of Contents

Introduction

SharePoint has an out-of-box feature to extract metadata such as To, From, CC and Subject from Exchange's EML file and save it in a column, however, SharePoint cannot do the same for MSG files hence this article describes how to use power shell to extract metadata
from MSG files and update a SharePoint list.

Setting the scene

Consider a scenario where you have several MSG files that you want to store in a SharePoint document library and in the process extract metadata from it. The MSG files are in a document library
and a list will have the metadata and somehow a relationship is built between them.

Requirements

1. PowerShell with SharePoint2010 or 2013 module

2. Notepad to edit the PS1 file

3. Temporary location to extract the Exchange MSG files

4. An open source application to unzip MSG files. In this example we are using 7-zip.

5. A SharePoint document library and list.

Document Library and List

A document library called 'EmailDocs' currently exists with several MSG files present there. We also have a custom list called 'EmailDocs2' with new columns added. Below are screenshots of both EmailDocs and EmailDocs2's settings.

EmailDocs

Below is a screenshot of the Subject column. If you have created the EmailDocs with the Content Type as Document the you should have a 'Copy Source' column available.

EmailDocs2

The PowerShell scripts

There are two scripts, one is to download the MSG files from the document library and second is to extract the metadata and add them to the list. You can also
CLICK HERE to down the ZIP file that has both the scripts combined.

Conclusion

You can take the above method a step further to download only the new MSG files that have been added, extract the metadata from it and update the list. This can very easily be done by adding a Yes/No column with default No and calling it something similar to
'DataExtracted' such that after the data is extracted the script will change the No to Yes. Also, you will have to add both the scripts to a Task Schedule on the server to run as often as you would like it.