Getting Inactive Office365 groups

Featured image

In the previous blog we have learned how to restrict the permission of creating new Office365 Groups to a specific security group. There are scenarios where lot of office365 groups created and there are no conversations in those Office365 Groups.

In this blog we are going to check how to retrieve the inactive Office365 Groups.

We are going to use the following PowerShell cmdlets

  1. Get-UnifiedGroup - Retrieves the Office365 Groups
  2. Get-MessageTrace - Retrieves all the messages passed through your Office365 service

Steps involved to achieve this

  1. Get all the Office365 Groups
  2. Get all the messages passed through your Office365 service for last ‘N’ days. Here ‘N’ denotes the number of inactive days.
  3. Now check what are the Office365 Group’s addresses that are not found in the message trace. These are the inactive Office365 Groups.

Powershell script

                            $InactiveDays = 30 //replace with required days
                            $Groups= Get-UnifiedGroup
                            $messages = Get-MessageTrace -startdate ([system.DateTime]::Now.AddDays(-$InactiveDays)) -enddate ([system.DateTime]::Now.AddDays(+1)) |where-object{$_.Status -like "Expanded" -or $_.Status -like "Delivered"}
                            $Groups | Foreach-Object{     
                            $Group = $_
                            $LastTime =  $messages  | where-object{$_.RecipientAddress -Like $Group.PrimarySmtpAddress}             
                            If($LastTime.Received -eq $null)
                            New-Object -TypeName PSObject -Property @{      
                             }}}|select Groupname,GroupType,EmailAddress

Performance with message tracing

The look back period for message tracing data is 90 days. And also when you query for message trace less than 7 days, it will take 5-30 minutes and for more than 7 days , the result will take few hours. Said this limitation you can retrieve the inactive Office365 Groups for 3 months alone. MSDN Reference:

With our product GingerEx for Office365, a simple desktop app which stores the old data in DB. With our product you can overcome 90 days limitation for message tracing and also the performance will be good, since querying is done in DB instead of directly against your Office365 tenant.

GingerEx for Office365 is free for tenants with less than 50 seats, you can download it from here .