main logo

Listing Microsoft 365 Groups with PowerShell: A Complete Guide

Microsoft 365 Groups

Microsoft 365 Groups provide seamless collaboration by integrating services like Outlook, SharePoint, and Teams. Administrators often need to manage these groups, including listing all groups and modifying their settings. A common task is to list all Microsoft 365 Groups in the tenant to identify primary and alias email addresses. This guide explains how to use PowerShell to efficiently gather this information and manage email aliases.

Understanding the Requirement

Why List Microsoft 365 Groups?

Listing Microsoft 365 Groups is essential for several administrative tasks, including:

  • Auditing groups and their associated email addresses.
  • Bulk management of alias (secondary) email addresses.
  • Ensuring compliance with organizational naming conventions.
  • Identifying inactive groups for potential cleanup.

Primary and Alias Email Addresses

  • Primary Email Address: Represented by SMTP in uppercase.
  • Alias (Secondary Email Address): Represented by smtp in lowercase. Alias addresses allow a group to receive emails sent to alternative addresses.

Prerequisites

Before starting, ensure the following:

1. Install the Exchange Online PowerShell Module: Use this command to install the module:

Install-Module -Name ExchangeOnlineManagement

2. Connect to Exchange Online: Authenticate and connect to Exchange Online PowerShell with the command:

    Connect-ExchangeOnline -UserPrincipalName <your_admin_email>

    Replace <your_admin_email> with your administrator email address.

    3. Permissions: Ensure the account used has the necessary permissions to view and manage Microsoft 365 Groups.

      Listing Microsoft 365 Groups with PowerShell

      Step 1: Retrieve Group Information

      To list all groups, use the Get-UnifiedGroup cmdlet. This command retrieves detailed information about each Microsoft 365 Group in the tenant.

      Basic Command:

      Get-UnifiedGroup

      This returns a list of all groups, but without detailed email address information. To include email addresses, modify the script as follows:

      Step 2: Extract Email Addresses

      Run this script to display each group’s name, primary email, and alias addresses:

      # Fetch all Microsoft 365 Groups $groups = Get-UnifiedGroup# Loop through each group to display email addresses $groupDetails = $groups | ForEach-Object { [PSCustomObject]@{ GroupName = $_.DisplayName PrimarySMTP = $_.PrimarySmtpAddress AliasAddresses = ($_.EmailAddresses -ne $_.PrimarySmtpAddress) -join “, ” } }# Output the details $groupDetails | Format-Table -AutoSize# Optional: Export the details to a CSV file $groupDetails | Export-Csv -Path “M365GroupsWithAliases.csv” -NoTypeInformation -Encoding UTF8

      Explanation:

      • Primary SMTP Address: The main email address used by the group.
      • Alias Addresses: Alternative email addresses associated with the group, excluding the primary address.
      • Export to CSV: Saves the details in a file for easy analysis.

      Managing Alias Addresses

      Step 1: Identify Groups to Update

      After listing the groups, determine which aliases need removal. Create a CSV file (AliasesToRemove.csv) with the following format:

      GroupIdAlias
      Group1_IDalias1@example.com
      Group2_IDalias2@example.com

      Step 2: Remove Alias Addresses in Bulk

      Use the following script to remove aliases:

      # Read the CSV file with alias addresses to remove $aliasesToRemove = Import-Csv -Path “AliasesToRemove.csv”# Loop through each group and remove aliases foreach ($entry in $aliasesToRemove) { $groupId = $entry.GroupId $aliasToRemove = $entry.Alias# Remove alias Set-UnifiedGroup -Identity $groupId -EmailAddresses @{Remove=$aliasToRemove} }

      Notes:

      • Backup Data: Before making changes, back up the group’s current settings.
      • Test Changes: Apply changes to a few test groups to ensure the script works as intended.

      Preventive Best Practices

      • Audit Regularly: Schedule periodic audits of Microsoft 365 Groups to maintain consistency.
      • Document Changes: Maintain records of changes made to groups for compliance and troubleshooting.
      • Minimize Alias Usage: Limit alias addresses to reduce administrative overhead.

      Why Choose Medha Cloud for Microsoft 365 Management?

      Managing Microsoft 365 Groups effectively requires expertise and precision. Medha Cloud provides:

      • Comprehensive Group Audits: Ensure all groups are compliant and optimized for performance.
      • Streamlined Alias Management: Simplify alias creation, modification, and removal.
      • Custom PowerShell Solutions: Tailored scripts to meet your specific organizational needs.
      • 24/7 Support: Get expert assistance whenever you need it.

      Contact Medha Cloud to streamline your Microsoft 365 administration and optimize your collaboration environment.

      Conclusion

      Listing Microsoft 365 Groups and managing their alias addresses is a critical task for administrators. By leveraging PowerShell, you can automate and simplify these operations, saving time and reducing errors. Follow the steps outlined in this guide to efficiently list groups, extract email details, and manage aliases. For expert support and advanced solutions, trust Medha Cloud to handle all your Microsoft 365 needs.

      Benjamin Gbolaru
      Benjamin Gbolaru
      I'm Benjamin, a Microsoft 365 Specialist, helping small and large businesses deploy, configure, and secure M365 environments to maximize the benefits of Microsoft tools. With sound expertise in driving cloud adoption, identity and access management (IAM), security monitoring, system reliability, and proactive troubleshooting.
      Share
      Contents

      Related Articles

      medhacloud logo
      USA:
      Medha Cloud Solutions LLC
      30 N Gould St Ste R, Sheridan, WY 82801,
      Phone: +1 646 775 2855

      India:
      Medha Cloud Solutions Private Limited
      #74, 7th Cross, Krishna Garden InCity Layout. Chikka Kammanahalli, Banneraghatta Road, Bangalore 560083
      Phone:+91 93536 44646

      E-Mail: sales@medhahosting.com
      ©Medha Cloud 2024. All rights reserved.