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

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.

  • Find the sites where the email files are stored. By definition, the sites are linked to Teams, so the task is to find teams with email-enabled channels (or rather, the Microsoft 365 groups linked to the teams). I used this script to do the job and create a CSV file for input into the main script. In large tenants, you could split the CSV file into several files to spread the load across multiple jobs.
  • Define an age threshold for archiving. I decided to archive any email file more than three years old.
  • Import the CSV file to define which groups to process. If the input file isn’t available, the script processes every Microsoft 365 group in the tenant.
  • For each group, use the Get-MgGroupSite cmdlet to find the associated SharePoint site.
  • Run the Get-MgSiteDrive cmdlet to find the drives (document libraries) for the site. Remove drives that we don’t want to process, like the Preservation Hold library.
  • For each drive, fetch the set of files and folders in the drive root and work through the drive to find any folders used to hold email messages received through a team channel.
  • Check each file in the folders and archive any older than the threshold date.

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).

The script runs to archive mail files stored in SharePoint Online.
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.

Archived files viewed through SharePoint Online.

File-level archiving
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.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.