Revisiting the Office 365 Groups and Teams Activity Report

Office 365 with Teams

A Year On, Time to Revise

In January 2018, I published “Finding Obsolete Office 365 Groups with PowerShell,” describing a script to analyze the Office 365 Groups in a tenant and report on whether some of the groups might be obsolete because they aren’t used. The script is available in the TechNet gallery for anyone who wants to download a copy.

A year or so later, it was time to look at the script and improve it. Teams is more important now and we have a rapidly changing Teams PowerShell module, so the kludge used to detect if an Office 365 group is team-enabled is no longer necessary. In fact, there’s several ways to check.

Checking for Teams

I could have depended on the setting Teams uses to hide its groups from Exchange clients and used a command like the one below to find these groups:

Get-UnifiedGroup | ? {$_.HiddenFromExchangeClientsEnabled -eq $True}

The problem is that the command uses a client-side filter so it’s slow. Because it checks so many aspects of a group, the Get-UnifiedGroup cmdlet is already slow, so adding an extra layer of slowness isn’t a good thing. But a more fundamental problem is that Teams only started to hide its groups from April 2018 and any early team-enabled group does not have this setting. In my tenant, roughly a third of the team-enabled groups were marked.

Another idea is to use the external directory object identifier returned for each group with a command like Get-TeamChannel to test whether any channels exist for that identifier. Code like this would work.

If (Get-TeamChannel -GroupId (Get-UnifiedGroup -id "Office 365 for it pros").ExternalDirectoryObjectId)      
    { Write-Host "Some Channels Exist"}

Checking for the presence of channels works, but again might be slow when a tenant supports hundreds or thousands of teams.

In the end, I chose to use the Get-Team cmdlet to fetch a list of teams and load them into an array. Get-Team is a very simple cmdlet and runs very quickly. All I loaded into the array was the identifier for each team. I could then check the identifier fetched for a group against the array to quickly discover if the group is team-enabled.

Upgrades and Progress

Apart from upgrading the script to deal more elegantly with Teams, I made several changes to improve the code, like dealing with groups with no owners more precisely. Some better checking is now done against the compliance records logged for Teams in the Team Chat folder to figure out whether the team is active.

Updates like the ability to deal with site designs appeared in the SharePoint PowerShell module during 2018, but nothing came along to help me figure out the level of activity within a site, so much the same code is used for that.

On an aesthetic note, the script now displays a progress bar (Figure 1) to tell you how many of the available groups have been processed.

Figure 1: Progressing through groups and teams (image credit: Tony Redmond)

The script now generates a CSV file as well as a HTML report. Creating a CSV file from the gathered data is an easy one-line addition that delivers a lot of value. It’s often easier to analyze information about a large set of items through Excel (Figure 2), or if you prefer, by loading the CSV data into Power BI.

Figure 2: The CSV file with group activity data (image credit: Tony Redmond)

More Improvements?

As I pointed out in the original article, I am not a professional programmer. The PowerShell that I produce is the result of hours of happy hacking and it’s ripe for improvement by people who know better. I look forward to seeing what the PowerShell pros can do. In the meantime, I’ll keep on my path of incremental improvement.