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.
Listing Microsoft 365 Groups is essential for several administrative tasks, including:
SMTP
in uppercase.smtp
in lowercase. Alias addresses allow a group to receive emails sent to alternative addresses.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.
To list all groups, use the Get-UnifiedGroup
cmdlet. This command retrieves detailed information about each Microsoft 365 Group in the tenant.
Get-UnifiedGroup
This returns a list of all groups, but without detailed email address information. To include email addresses, modify the script as follows:
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
After listing the groups, determine which aliases need removal. Create a CSV file (AliasesToRemove.csv
) with the following format:
GroupId | Alias |
---|---|
Group1_ID | alias1@example.com |
Group2_ID | alias2@example.com |
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} }
Managing Microsoft 365 Groups effectively requires expertise and precision. Medha Cloud provides:
Contact Medha Cloud to streamline your Microsoft 365 administration and optimize your collaboration environment.
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.