Coming Soon: GET-IT: Endpoint Management 1-Day Conference on September 28th at 9:30 AM ET Coming Soon: GET-IT: Endpoint Management 1-Day Conference on September 28th at 9:30 AM ET
Microsoft Teams|Office|Office 365

Emailing Owners About Obsolete Office 365 Groups and Teams

PowerShell ISE and script

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

Sponsored Content

Say Goodbye to Traditional PC Lifecycle Management

Traditional IT tools, including Microsoft SCCM, Ghost Solution Suite, and KACE, often require considerable custom configurations by T3 technicians (an expensive and often elusive IT resource) to enable management of a hybrid onsite + remote workforce. In many cases, even with the best resources, organizations are finding that these on-premise tools simply cannot support remote endpoints consistently and reliably due to infrastructure limitations.

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.

Example of a notification message for an obsolete Office 365 group
Figure 1: Example of a notification message for an obsolete Office 365 group (image credit: Tony Redmond)

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.


Don't have a login but want to join the conversation? Sign up for a Petri Account

Comments (0)

Leave a Reply

Tony Redmond has written thousands of articles about Microsoft technology since 1996. He covers Office 365 and associated technologies for and is also the lead author for the Office 365 for IT Pros eBook, updated monthly to keep pace with change in the cloud.
Live Webinar: Active Directory Security: What Needs Immediate Priority!Live on Tuesday, October 12th at 1 PM ET

Attacks on Active Directory are at an all-time high. Companies that are not taking heed are being punished, both monetarily and with loss of production.

In this webinar, you will learn:

  • How to prioritize vulnerability management
  • What attackers are leveraging to breach organizations
  • Where Active Directory security needs immediate attention
  • Overall strategy to secure your environment and keep it secured

Sponsored by: