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 : [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
Passwords Haven’t Disappeared Yet
123456. Qwerty. Iloveyou. No, these are not exercises for people who are brand new to typing. Shockingly, they are among the most common passwords that end users choose in 2021. Research has found that the average business user must manually type out, or copy/paste, the credentials to 154 websites per month. We repeatedly got one question that surprised us: “Why would I ever trust a third party with control of my network?
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.