Site icon Microsoft 365 for IT Pros

How to Archive Old Teams Channel Email Files with Microsoft 365 Archive

File-level archiving for email sent to Teams.
Advertisements

Use File-Level Archiving to Move Old Message Files from SharePoint Online

In May 2026, Microsoft released the public preview of file-level archiving for SharePoint Online. It’s a good idea to move old files into the archive to reduce storage costs while retaining access to the files if they are ever needed. Archived files are unavailable for search and retrieval, which prevents AI tools like Microsoft 365 Copilot from using their content in generated responses. Archived files are also unavailable to third-party AI tools from Claude and OpenAI. File-level archiving is now generally available.

A beta Graph API is available to automate file-level archiving operations. To put the API to the test, I decided to archive the many thousands of emails captured in SharePoint Online when someone sends email to a team channel. This facility was more popular a few years ago than it seems to be today, but it remains a useful way to preserve copies of messages sent to distribution lists. In that respect, it resembles the old practice of including a public folder in a distribution list. In any case, SharePoint Online uses a set of folders under the “Microsoft Teams Mailhook” folder to store the emails, with a new folder created monthly.

I wrote some code to figure out how many email (.eml) files were in SharePoint and found 11,765 occupying approximately 1.5 GB of storage. My tenant is small, but it hosts several “Outlook groups” used for email-based discussion. The messages captured in SharePoint go back to 2018, and most of the files are well past their best-by date, especially when Copilot might decide to use the information in the files.

Scripting a Solution

The steps required to find and archive email files in SharePoint Online are straightforward.

Before starting, you’ll need to configure a billing policy for Microsoft 365 Archive. No charges will be incurred unless your tenant exhausts the available SharePoint Online storage quota because Microsoft 365 Archive offsets its usage against the SharePoint quota.

The script runs a Microsoft Graph PowerShell SDK session in app-only mode. It requires the Files.ReadWrite.All permission to archive files, the Sites.Read.All permission to read site details, and the GroupMember.Read.All permission to read details of groups. At the end of its processing, the script generates some basic statistics (Figure 1).

Figure 1: The script runs to archive mail files stored in SharePoint Online

Figure 2 shows one of the email folders with a set of archived messages.

Figure 2: Archived files viewed through SharePoint Online

I don’t claim that the script is bulletproof. It works, which is all I ever want. No doubt some enhancements are possible, and I’ll leave those to folks who are more skilled with PowerShell than I am.

Running File-Level Archiving Scripts in Azure Automation

You can download the complete script from the Microsoft 365 for IT Pros GitHub repository. This kind of script is very suitable for processing as an Azure Automation runbook. Be aware that the maximum run time for a runbook is three hours. Depending on the number of sites, folders, and files to process, it’s possible that the script could exceed three hours, especially for the first run. After that, because many of the .eml files stored in SharePoint will already be archived, the time required to process the remainder should be shorter.

My advice is to start with a small amount of data and build from that point. Also be aware that the free tier of Azure provides 500 minutes of runtime monthly. After that, you’ll be charged.

Retention Label is the Alternative

The alternative to writing a script is to configure a retention auto-label policy to apply a retention label which includes an archival step in its retention settings. However, that capability is only just rolling out and has been delayed several times. Auto-labeling also requires E5 licenses. And besides, who would use a black box run by Microsoft to archive files when you can do the job yourself with PowerShell? The answer is most people…


So much change, all the time. It’s a challenge to stay abreast of all the updates Microsoft makes across the Microsoft 365 ecosystem. Subscribe to the Microsoft 365 for IT Pros eBook to receive insights updated monthly into what happens within Microsoft 365, why it happens, and what new features and capabilities mean for your tenant.

Exit mobile version