Finding specific messages or threads using search tools within Microsoft Teams chat history
To retrieve all Microsoft Teams chat messages for a user across a specific date range (for example, 01/01/2024–08/31/2025), use Microsoft Graph’s Teams chat export APIs and then filter by date in the client or processing logic.
Below is a practical approach using Microsoft Graph and (optionally) Graph PowerShell.
- Use chats getAllMessages to export all chat messages
Use the application permission API to pull all chat messages for the user, then filter locally to the desired date range.
HTTP request:
GET /users/{id-or-upn}/chats/getAllMessages
Notes:
- Returns all messages from all chats (1:1, group, and meeting chats) in which the user is a participant.
- Requires an app with
Chat.Read.All(orChat.ReadWrite.All) application permission and admin consent. - Use this when messages may be older than 8 months, or when a full export is needed. After retrieving, filter messages where
createdDateTimeis between2024-01-01T00:00:00Zand2025-08-31T23:59:59Z.
- Use chatMessage delta for ongoing sync (last 8 months)
If only the last 8 months are needed, or after an initial export, use the delta API to keep data up to date.
- The delta API returns messages from all chats in which the user participates and supports full and incremental sync.
- It only returns messages from the last eight months; for older content, use
getAllMessages.
Process:
- Call the delta function to get an initial full sync of the last 8 months.
- Save the
@odata.deltaLinkfrom the response. - For subsequent runs, call the URL in
@odata.deltaLinkto get only new/changed messages. - In each response, filter messages by
createdDateTimeinto the desired date window. - PowerShell options with Microsoft Graph PowerShell SDK
If using PowerShell, the Teams module exposes delta-based cmdlets that align with the REST APIs:
-
Get-MgUserChatMessageDelta -
Get-MgChatMessageDelta
These cmdlets:
- Return messages from all chats in which the user is a participant.
- Support delta query semantics (
@odata.nextLink/@odata.deltaLink).
Example high-level flow (pseudo-steps):
- Connect with an app that has
Chat.Read.Allapplication permission. - Run
Get-MgUserChatMessageDelta -UserId <userId>to get messages. - Store the delta link for incremental runs.
- Filter the returned objects by
createdDateTimebetween 2024-01-01 and 2025-08-31.
The -Search parameter exists on these cmdlets, but the context only documents it as a simple string parameter; use it for keyword searches if needed, and still apply date filtering in PowerShell (for example, with Where-Object on createdDateTime).
- Identifying all employees chatted with in that period
Once messages are exported and filtered by date:
- Extract the participants (sender and recipients) from each message.
- Build a distinct list of user IDs or display names from those messages.
- That list represents all employees the user had chats with between 01/01/2024 and 08/31/2025, including those no longer visible in the Teams client.
Summary:
- Use
GET /users/{id}/chats/getAllMessagesfor a complete export, then filter bycreatedDateTimefor 01/01/2024–08/31/2025. - Use
chatMessage: delta(orGet-MgUserChatMessageDelta/Get-MgChatMessageDelta) for ongoing incremental sync (last 8 months), again filtering bycreatedDateTime. - From the filtered messages, derive the list of all employees involved in chats in that date range.
References: