Retrieve Microsoft Teams User Activity Reports with Graph PowerShell

The Get-MgReportTeamUserActivityUserDetail cmdlet is part of the Microsoft Graph PowerShell module and is essential for administrators who need to retrieve detailed user activity reports for Microsoft Teams. This cmdlet helps in monitoring and analyzing the usage of Teams within an organization which is crucial for optimizing productivity and ensuring compliance.


Prerequisites

  • Graph PowerShell module installed (Microsoft.Graph).
  • Necessary Microsoft 365 admin role to access teams activity reports.
  • Basic knowledge of PowerShell scripting.

Installing the Microsoft Graph PowerShell Module

If you haven't installed the Graph PowerShell module yet, you can do so by running:

Install-Module Microsoft.Graph -Scope CurrentUser


Connecting to Microsoft Graph

First, you need to connect to Microsoft Graph with the required Graph API permission "Reports.Read.All":

Connect-MgGraph -Scopes "Reports.Read.All"
You will be prompted to authenticate. Ensure you log in with an account that has sufficient permissions.


Get-MgReportTeamUserActivityUserDetail Overview

The Get-MgReportTeamUserActivityUserDetail cmdlet generates a detailed report of user activities in Microsoft Teams for a specified date or period. The report includes various metrics such as the number of messages sent, meetings attended, and other collaborative activities.


Get-MgReportTeamUserActivityUserDetail Syntax


Get-MgReportTeamUserActivityUserDetail -Date  -OutFile  [-ResponseHeadersVariable <String>] [-Headers <IDictionary>] [-PassThru] [-ProgressAction <ActionPreference>] [<CommonParameters>]

Get-MgReportTeamUserActivityUserDetail -Period <String> -OutFile <String> [-ResponseHeadersVariable <String>] [-Headers <IDictionary>] [-PassThru] [-ProgressAction <ActionPreference>] [<CommonParameters>]


                            

Parameters


  • -Date: Specifies the date for the report. This parameter is required if -Period is not specified.
  • -Period: Specifies the period for the report such as D7 for the last 7 days, D30 for the last 30 days, etc. This parameter is required if -Date is not specified.
  • -OutFile: Specifies the path where the output file will be written. This parameter is required.
  • -ResponseHeadersVariable: Optional. Stores the headers from the HTTP response.
  • -Headers: Optional. Adds additional headers to the HTTP request.
  • -PassThru: Optional. Returns true if the command succeeds.
  • -ProgressAction: Optional. Specifies how the progress of the command is shown.

Example Usage


Example 1: Generating a Report for a Specific Date

Get-MgReportTeamUserActivityUserDetail -Date "2024-06-01" -OutFile "C:\Reports\TeamsUserActivity_June1.csv"

This command generates a user activity report for June 1, 2024, and saves it to the specified file.


Example 2: Generating a Report for the Last 7 Days

Get-MgReportTeamUserActivityUserDetail -Period "D7" -OutFile "C:\Reports\TeamsUserActivity_Last7Days.csv"

This command generates a user activity report for the last 7 days and saves it to the specified file.


Practical Usage Scenarios


  • Monitoring Team Engagement: By regularly generating and analyzing user activity reports, administrators can monitor engagement levels across the organization. This helps in identifying users who might need additional training or support.
  • Ensuring Compliance: Activity reports can be used to ensure that team communication and collaboration adhere to organizational policies and compliance requirements.
  • Optimizing Resources: Analyzing the usage patterns helps in optimizing resources, such as adjusting the number of licenses or enhancing support for high-usage periods.

Frequently Asked Questions

How long are deleted users retained before they are permanently removed? Deleted users are retained in Azure AD for 30 days by default. After this period, they are automatically and permanently deleted.

  • How far back can I retrieve Teams user activity reports?
  • You can retrieve reports for up to 180 days by using the -Period parameter values such as D7, D30, D90, or D180. Anything beyond 180 days is not available through Graph PowerShell.

  • Can I export the Teams user activity report for offline analysis?
  • Yes. You can pipe the output into Export-Csv to generate a structured file for reporting or auditing purposes.

  • Do Teams activity reports include guest users?
  • Yes. Guest users are included in the reports, which helps administrators track external collaboration within Teams.

  • Is it possible to automate the retrieval of Teams activity reports?
  • Absolutely. You can schedule your Graph PowerShell script using Windows Task Scheduler or Azure Automation to automatically fetch reports on a recurring basis.

Example Errors and Solutions

Error Cause Solution
Invalid date format Verify that the date is in the correct YYYY-MM-DD format. Get-MgReportTeamUserActivityUserDetail -Date "2023-06-01" -OutFile "C:\Reports\TeamsUserActivity.csv"
Access Denied Ensure that the executing account has the necessary permissions in Azure AD and that the Microsoft Graph API permissions are correctly configured. The executing account should have the Reports.Read.All permission assigned to it to execute this cmdlet.

⏳ Reporting Data Is Limited to a Maximum of 180 Days

Microsoft Graph only retains Teams user activity report data for the past 180 days.

Using values like D270 or anything beyond this limit in the -Period parameter will result in an error.
📊 The -Period Parameter Returns Time-Bound, Pre-Aggregated Reports

The -Period parameter (e.g., D7, D30, D90, D180) is required when retrieving Teams user activity reports.

It lets you access summarized activity data without additional date filtering — just be sure to use one of the supported values.

📊 Use -Period to Control Report Range

When retrieving Teams user activity reports, the -Period parameter lets you specify the time frame (e.g., D7, D30, D90, D180.). Match the period to your analysis needs — D7 for weekly usage checks, D30 for monthly trends, or D90/D180 for quarterly/half-year adoption insights.


Additional Resources


Conclusion

By understanding and utilizing the Get-MgReportTeamUserActivityUserDetail cmdlet, administrators can effectively monitor and manage Teams usage within their organization, ensuring optimal performance and compliance.


Related Articles:

Using Get-MgDirectoryRole in Graph PowerShell
Using Get-MgUserLicenseDetail in Graph PowerShell
Using Find-GraphMgCommand in Graph PowerShell
Connect to Microsoft 365 Using PowerShell
How to Create Bulk Users in Office 365 Using Graph PowerShell?
Create Microsoft 365 Group Using Microsoft Graph PowerShell
Block Microsoft 365 User Using Microsoft Graph PowerShell
Assign Microsoft 365 License Using Graph PowerShell
Microsoft 365 User Management Using Graph PowerShell
Checking Group Membership in Microsoft 365
Bulk Assign Microsoft 365 License
Find Inactive Users in Microsoft 365
Using Powershell Graph Search Query
Using Powershell Graph Filter Query
Using Where-Object In Graph PowerShell
Using Expand Property In Graph PowerShell
Using Select Object In Graph PowerShell
Using -Contains Operator In Graph PowerShell
Add User to Multiple Microsoft 365 Groups Using Graph PowerShell
Import Microsoft 365 Groups from CSV File Using Graph PowerShell
Microsoft 365 Group User Import Using Graph PowerShell

© m365corner.com. All Rights Reserved. Design by HTML Codex