Petri Newsletter Sign-up
Tech Tuesday

Subscribe to Tech Tuesday, the latest insights from Petri.com for IT Pros.

    See All Petri Newsletters

    Emailing Owners About Obsolete Office 365 Groups and Teams

    Posted on by Tony Redmond in Microsoft Teams, Office, and Office 365

    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:

    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.

    BECOME A PETRI MEMBER:

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

    Register

    Register for this Petri Webinar!

    Want to Make Your Backup Storage Unlimited & Ready for the Cloud? – Free Thurrott Premium Account with Webinar Registration!

    Tuesday, August 27, 2019 @ 1:00 pm EDT

    A Scale-Out Backup storage infrastructure is a must-have technology for your backups. In this webinar, join expert Rick Vanover for a look on what real-world problems are solved by the Scale-Out Backup Repository.

    Register Now

    Sponsored By