⚠️ This is a refactored fork of telstrapurple/MSTeamsChatExporter. See MODIFICATIONS.txt for a detailed list of changes.
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.
- ✅ 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
- PowerShell 7 (Install Guide)
- Microsoft 365 account
- Azure AD App Registration with delegated permissions:
Chat.ReadUser.ReadUser.ReadBasic.All
Follow these guides to register and configure the app:
- Download this repository
- Create a folder where you'd like to export your chat history
- Open PowerShell 7
- Run the script with the
Get-Helpcommand to view available parameters:
PS> Get-Help ./Get-MicrosoftTeamsChat.ps1- 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"-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 -ConfirmMSTeamsChatExporter/
├── 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
Feel free to contribute and make this script better. Suggestions and improvements are welcome!
- 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
MIT (same as the original project)