Updating the Office 365 Groups and Teams Activity Report Script

V4.1 Now Available in the TechNet Gallery

January 15: Script updated to V4.1. See note below.

I wrote the first version of a script to analyze the activity in Office 365 Groups and Teams to identify obsolete groups in 2017. The script is was last updated in 2018 (see the Petri.com article) and is reasonably popular. Some recent feedback prompted me to review it to see if I could improve the code. The result of that work is now available for download from the TechNet Gallery.

The basic idea for the script remains. Find all the Office 365 Groups in a tenant and figure out what level of activity there is in terms of conversations (for Outlook Groups), documents (in SharePoint document libraries belong to the groups), and chats (for groups enabled for Teams). The outputs are an HTML report and a CSV file. We also assign a status of Pass, Warning, or Fail to each group depending on the level of detected activity. The determination of the status is entirely arbitrary and should be adjusted to meet the needs of your organization.

Office 365 Groups and Teams Activity Report
Figure 1: Office 365 Groups and Teams Activity Report

Reviewing the report should help you find Office 365 Groups and Teams that are not being used. These groups are candidates for removal or archival.

Improvements in V4.0

I didn’t want to rewrite the script as I didn’t have the time. However, I made some changes that I think are useful.

  • New tests to see if the SharePoint Online and Teams modules are loaded. In particular, the Teams check took far too long because the cmdlets in this module are slow.
  • Use a PowerShell list object to store the report data. This is much faster than an array, especially when you might want to store data for thousands of groups. This was one of the performance tips received after publishing a post about how we write PowerShell and it makes a real difference.
  • Use Get-Recipient instead of Get-UnifiedGroup to create a set of group objects to process. Get-Recipient is much faster than Get-UnifiedGroup when you need to create a list of mail-enabled objects like Office 365 Groups.
  • Output the storage consumed by the SharePoint site belonging to each group.

I didn’t use the new Exchange Online REST-based cmdlets to replace Get-Recipient with Get-ExoRecipient and Get-MailboxFolderStatistics with Get-ExoMailboxFolderStatistics. The Exchange Online Management module for these cmdlets is still in preview, so I decided to stay with the standard cmdlets. In a large environment, you might get some extra performance by using Get-ExoRecipient. There is no REST-based version of Get-UnifiedGroup.

Those who manage groups in large environments could also improve processing by using the techniques explained in this EHLO blog post.

Change in V4.1

Shortly after posting this note, someone who used the script reported a problem reporting the number of Teams compliance items. Apparently, all he ever saw reported for the number of chats was 1, even for active teams. Looking at the code, I realized that I could be more precise in the check for items by looking for a subfolder of type “TeamChat” and fetching the data from there. This change is in V4.1 as published in the TechNet Gallery.

I also took the chance to add the creation date and the number of days old for each group in the output report.

Test Before Deployment

As always, test any PowerShell code downloaded from the web, even from sources like the TechNet Gallery, before introducing it to a production system. The code as written needs some extra error handling to make it as robust as it could be, but I’ve left that to the professionals as people tend to have their own way of approaching this issue.


The Office 365 for IT Pros eBook includes many valuable tips for writing PowerShell scripts to interact with Office 365 Groups and Teams. Subscribe to gain benefit from all that knowledge!

Advertisements

One Reply to “Updating the Office 365 Groups and Teams Activity Report Script”

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.