How to retrieve and analyze Microsoft 365 usage data with PowerShell

How to retrieve and analyze Microsoft 365 usage data with PowerShell

Retrieving and analyzing Microsoft 365 usage data with PowerShell can provide valuable insights into how your organization is using Microsoft 365 services, which can help you optimize your environment and improve user productivity. In this step-by-step guide, we will explore how to retrieve and analyze Microsoft 365 usage data using PowerShell.



Step 1: Install Required Modules


To get started with Microsoft 365 PowerShell, you need to install the following module:

  • Microsoft 365 Usage Analytics PowerShell Module


You can download this module from the Microsoft website or install it using the PowerShell Gallery.


To install the Microsoft 365 Usage Analytics PowerShell module, run the following command in PowerShell:


  1. Install-Module-Name Microsoft365UsageAnalytics



Step 2: Connect to your Microsoft 365 Tenant


To connect to your Microsoft 365 tenant, run the following command in PowerShell:


  1. Connect-M365UsageAnalytics -Credential (Get-Credential)


This will prompt you to enter your Microsoft 365 admin credentials. Once you have authenticated, you can start using PowerShell to retrieve and analyze Microsoft 365 usage data.



Step 3: Retrieve Microsoft 365 Usage Data


There are many types of usage data that you can retrieve from Microsoft 365 using PowerShell. Here are some examples:


1. Retrieve User Activity Data


You can retrieve user activity data from Microsoft 365 to see how users are interacting with Microsoft 365 services. To retrieve user activity data using PowerShell, run the following command:


  1. Get-M365UserActivity -StartDate "2022-01-01" -EndDate "2022-03-31" -GroupBy UserPrincipalName


This command retrieves user activity data for the period between January 1, 2022, and March 31, 2022, and groups the data by user principal name.


2. Retrieve Tenant Activity Data


You can retrieve tenant activity data from Microsoft 365 to see how your organization is using Microsoft 365 services as a whole. To retrieve tenant activity data using PowerShell, run the following command:


  1. Get-M365TenantActivity -StartDate "2022-01-01" -EndDate "2022-03-31" -GroupBy Service


This command retrieves tenant activity data for the period between January 1, 2022, and March 31, 2022, and groups the data by service.



Step 4: Analyze Microsoft 365 Usage Data


Once you have retrieved Microsoft 365 usage data using PowerShell, you can use various data analysis tools and techniques to gain insights and identify trends. Here are some examples:


1. Use Excel to Create Pivot Tables


You can use Excel to create pivot tables that summarize and visualize Microsoft 365 usage data. To do this, export the data retrieved from PowerShell to a CSV file using the following command:


  1. Get-M365UserActivity -StartDate "2022-01-01" -EndDate "2022-03-31" -GroupBy UserPrincipalName | Export-Csv -Path "C:\Temp\UserActivity.csv" -NoTypeInformation


Then, open the CSV file in Excel and create a pivot table that summarizes the data by user principal name, service, or activity type.


2. Use Power BI to Create Dashboards


You can use Power BI to create dashboards that provide real-time insights into Microsoft 365 usage data. To do this, export the data retrieved from PowerShell to a CSV file using the following command:


  1. Get-M365TenantActivity -StartDate "2022-01-01" -EndDate "2022-03-31" -GroupBy Service | Export-Csv -Path "C:\Temp\TenantActivity.csv" -NoTypeInformation


Then, import the CSV file into Power BI and create visualizations and dashboards that provide a comprehensive view of Microsoft 365 usage data. You can use various chart types, such as bar charts, line charts, and pie charts, to display usage data by service, user, or activity type.


3. Use PowerShell to Automate Analysis Tasks


You can use PowerShell to automate analysis tasks and generate reports that provide insights into Microsoft 365 usage data. For example, you can create a PowerShell script that retrieves user activity data for the past month, calculates the total number of activities for each user, and sends an email report to the IT team.


To do this, use the following PowerShell commands:


  1. $StartDate = (Get-Date).AddMonths(-1).ToString('yyyy-MM-dd')
  2. $EndDate = (Get-Date).ToString('yyyy-MM-dd')
  3. $UserActivity = Get-M365UserActivity -StartDate $StartDate -EndDate $EndDate -GroupBy UserPrincipalName
  4. $UserActivity | Select-Object UserPrincipalName, Total | Sort-Object -Descending Total | ConvertTo-Html | Out-File C:\Temp\UserActivityReport.html
  5. Send-MailMessage -To"ITTeam@example.com" -From"Admin@example.com" -Subject "Monthly User Activity Report" -Body (Get-Content C:\Temp\UserActivityReport.html -Raw) -BodyAsHtml -SmtpServer "SMTPServer.example.com"


This script retrieves user activity data for the past month, calculates the total number of activities for each user, creates an HTML report, and sends it to the IT team via email.



Conclusion:


In conclusion, retrieving and analyzing Microsoft 365 usage data with PowerShell can provide valuable insights into how your organization is using Microsoft 365 services. By following the steps outlined in this guide, you can use PowerShell to retrieve usage data, analyze it using various data analysis tools, and automate analysis tasks to gain insights and optimize your Microsoft 365 environment.


    • Related Articles

    • Generate an Activity Report for Microsoft 365 Groups and Teams

      Introduction The activity reports available for Microsoft 365 groups and Teams can be beneficial for administrators in an organization. Microsoft 365 teams group activity reports provide insight into group activities, group workloads, group counts, ...
    • How to find unused Exchange Online mailboxes

      What are unused Exchange Online mailboxes and how to identify them? Unused Exchange Online mailboxes are user mailboxes which are currently not being used by their users. There are 3 ways in which we can identify if a mailbox is unused or not. They ...
    • How to monitor Microsoft 365 email and mailbox activity with PowerShell

      Monitoring Microsoft 365 email and mailbox activity with PowerShell can be a crucial part of managing your organization's email security and compliance. With PowerShell, you can quickly and easily automate the process of monitoring email and mailbox ...
    • Managing Microsoft 365 Compliance and Retention Policies with PowerShell

      Microsoft 365 provides a range of compliance and retention features that enable organizations to meet their legal, regulatory, and business requirements. These features include compliance policies, retention policies, and retention labels. PowerShell ...
    • How to configure Microsoft 365 security settings using PowerShell

      As more organizations move to the cloud, it is becoming increasingly important to ensure the security of their Microsoft 365 environment. Microsoft provides a range of security settings that can be configured to enhance the security of your ...