Skip to content

paulonajera/MSTeamsChatExporter

 
 

Repository files navigation

Microsoft Teams Chat Exporter (Refactored Fork)

⚠️ This is a refactored fork of telstrapurple/MSTeamsChatExporter. See MODIFICATIONS.txt for a detailed list of changes.

Overview

This tool allows Microsoft 365 users to export their personal Microsoft Teams 1:1 and group chat history using Microsoft Graph APIs. This version is modular, supports CLI parameters, and includes multiple output formats.

Features

  • ✅ Export personal chat history via Microsoft Graph API
  • 📂 Output formats: HTML (default), JSON, CSV
  • 🧰 Modular structure for easier maintenance
  • 💡 CLI parameters for better scripting and automation
  • 📅 (Planned) Options to split exports by date

Requirements

  • PowerShell 7 (Install Guide)
  • Microsoft 365 account
  • Azure AD App Registration with delegated permissions:
    • Chat.Read
    • User.Read
    • User.ReadBasic.All

Follow these guides to register and configure the app:

Getting Started

Steps

  1. Download this repository
  2. Create a folder where you'd like to export your chat history
  3. Open PowerShell 7
  4. Run the script with the Get-Help command to view available parameters:
PS> Get-Help ./Get-MicrosoftTeamsChat.ps1
  1. Run the script with required arguments:
PS> ./Get-MicrosoftTeamsChat.ps1 -ExportFolder C:\Users\<you>\OneDrive\ExportChat \ 
    -ClientId "0728c136-cc8c-4b29-bbb7-e20c5c35f53a" \ 
    -TenantId "b2541388-a22b-4b8d-b027-883ad6b445a7" \ 
    -Domain "contoso.com"

Optional Switches

  • -AsJson — export chats to JSON format
  • -AsCsv — export chats to CSV format
  • -NoImages — skips embedding images in HTML
  • -SplitByMonth — (planned) split messages into monthly files
  • -WhatIf - Preview actions without making any changes (dry run mode)
  • -Confirm - Prompt for confirmation before exporting each chat

💡 Use -WhatIf to test safely, and -Confirm when you want full control over which chats get exported.

Example:

./Get-MicrosoftTeamsChat.ps1 `
  -ExportFolder "C:\ExportTest" `
  -ClientId "<your-client-id>" `
  -TenantId "<your-tenant-id>" `
  -Domain "yourcompany.com" `
  -AsCsv -WhatIf -Confirm

File Structure

MSTeamsChatExporter/
├── Get-MicrosoftTeamsChat.ps1       # Entry point
├── Modules/
│   ├── GraphAPI.psm1                # Handles MS Graph auth + data
│   ├── ChatExporter.psm1            # HTML / JSON / CSV output
│   └── Utils.psm1                   # Logging, sanitization
├── MODIFICATIONS.txt                # Summary of changes
├── README.md                        # This file
├── LICENSE                          # MIT License

Contribution

Feel free to contribute and make this script better. Suggestions and improvements are welcome!

Original Improvement Ideas from Upstream

  • Add PowerShell 5.1 support for broader compatibility
  • Refactor loops to improve export speed with async or parallel operations
  • Handle HTTP 429 throttling gracefully (Microsoft Graph throttling)
  • Improve HTML efficiency by optionally skipping base64 image embedding
  • Add full code documentation and inline comments

License

MIT (same as the original project)

About

Code that helps an end-user export their Microsoft Teams Chat History to HTML

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • PowerShell 100.0%