Emailing Owners About Obsolete Office 365 Groups and Teams
Sending Email to Encourage Action
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.
Helping Group Owners Do the Right Thing
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 : Tony.Redmond@redmondassociates.org 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
Building a Script to Send Messages
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:
- Figure out the target address (group owner).
- Build the body of a message using details of the group. I used HTML to introduce some basic formatting.
- Send the message. Office 365 supports several methods for applications and devices to send email. I decided to authenticate against an account that has an Exchange Online mailbox and send the message using SMTP client submission. Remember that Exchange Online throttles the ability of a user to sending 30 messages per minute (and a total of 10,000 recipients daily). The account you use to send the messages must have enough quota to store the messages.
Script to Send Messages to Group Owners
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.
Code Improvements Welcome
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.
More in Office 365
M365 Changelog: (Updated) Loop components in Outlook Mail Preview
Oct 22, 2022 | Rabia Noureen
How to Schedule an Email in Outlook
Sep 14, 2022 | Siji Roy
ESPC22 Conference Discount for Petri Readers
Sep 6, 2022 | Russell Smith
Microsoft Defender for Office 365 Gets Differentiated Protection for Priority Accounts
Apr 14, 2022 | Rabia Noureen
Microsoft 365 Non-Profit Plans to Get a Price Hike in September
Apr 11, 2022 | Rabia Noureen
Microsoft to Launch Office 365 Government Secret Cloud in Mid-2022
Mar 29, 2022 | Rabia Noureen
Most popular on petri