In February, I wrote about a new version of the PowerShell script to generate a report about Office 365 Groups and Teams in a tenant. The inevitable comment came in that it’s all very well to have a report to tell you what groups and teams aren’t in active use, but it would be so much better to proactively contact the group owners to tell them that it’s time to consider if the group is worth keeping. If not, the group can be removed (and recovered if necessary within 30 days) or archived.
Some tenants have thousands of groups. Even in the best-managed tenant, it’s likely that 10% to 15% of groups have become obsolete. The need for the group has passed, its members are occupied with new challenges, or the topic simply didn’t deserve a group in the first place. No one can get very excited about contacting the owners of hundreds of disused teams and groups to point out that they need to review their groups and take appropriate action, so some automation is needed.
The report script generates a variable called $Report to store details of the Office 365 groups it processes. An example of the details for a sample group is:
GroupName : Video Viewers ManagedBy : Tony Redmond ManagerSMTP : [email protected] Members : 4 ExternalGuests : 0 Description : People who like videos MailboxStatus : Group Inbox Not Recently Used LastConversation : 20 Jun 2017 22:20:09 NumberConversations : 2 TeamEnabled : False LastChat : No chats NumberChats : 0 SPOActivity : No SPO activity detected in the last 90 days SPOStatus : Normal NumberWarnings : 2 Status : Fail Alias : videoviewers GroupId : 953b1d8f-cf9e-4e4a-bc23-76d090355560
It doesn’t take a lot of work to build a PowerShell script to process the data held in the output from the reporting script and find groups that are candidates for removal (for instance, if the report script determines their overall status to be a “Fail”). Once we know the target owners, we can generate email using the Send-MailMessage cmdlet. After selecting the groups to be processed, the basic steps are:
Now that we know the flow, we can write the script. I’ve posted the version I used on GitHub. There are obvious improvements that can be made in the script to add better error handling and so on. I’ve tested it with 200 Office 365 groups and the code works, but I can’t tell you what will happen if you run it for 10,000 groups. No doubt it will be slower, but I can’t say if some sort of limit will be hit. Figure 1 shows an example notification message generated by the script.
Feel feel free to improve, change, enhance, and otherwise alter the code to your heart’s content – and tell us what you’ve done by posting a comment here.