How to Get Microsoft 365 Groups Filtered by Owner Using PowerShell

How to Get Microsoft 365 Groups Filtered by Owner Using PowerShell

Why Filter Microsoft 365 Groups by Owner?

Sometimes, you need to identify which Microsoft 365 groups are owned or managed by a particular user. This is especially useful when offboarding users, auditing group ownership, or simply organizing your Microsoft 365 environment.

Full PowerShell Script

Below is the complete PowerShell script used to fetch Microsoft 365 groups based on a specific user’s ownership:

PowerShell
# Step 1: Get the DistinguishedName of the target user
Get-Mailbox -Identity "UserName" | Format-List DistinguishedName

# Step 2: Use that DistinguishedName to filter Microsoft 365 groups by owner
Get-UnifiedGroup -Filter {ManagedBy -eq 'DistinguishedName'} |
Select DisplayName, PrimarySmtpAddress, GroupType |
Export-Csv "C:\Users\Desktop\Information.csv" -NoTypeInformation

Step-by-Step Explanation of Each Line

PowerShell
Step 1 :
Get-Mailbox -Identity "UserName" | Format-List DistinguishedName

– Get-Mailbox : This command fetches mailbox details of the specified user.
– Identity “UserName” : Replace “UserName” with the actual UPN or alias of the user whose groups you want to check.
– Format-List DistinguishedName : This displays the unique path (DistinguishedName) used by Exchange to refer to the mailbox object.

PowerShell
Step 2 :
Get-UnifiedGroup -Filter {ManagedBy -eq 'DistinguishedName'}

– Get-UnifiedGroup : Retrieves all Microsoft 365 groups.
– Filter {ManagedBy -eq ‘DistinguishedName’} : Filters only those groups where the owner (ManagedBy) matches the specified DistinguishedName.

PowerShell
Select DisplayName, PrimarySmtpAddress, GroupType

– Select : Chooses specific columns to display: group name, email address, and type.

PowerShell
Export-Csv "C:\Users\Desktop\Information.csv" -NoTypeInformation

– Export-Csv : Saves the results into a CSV file for easier reporting.
– NoTypeInformation : Cleans up the output by removing type metadata.

Sample Output

Here’s what the CSV file (`Information.csv`) might look like after running the script:

| DisplayName       | PrimarySmtpAddress         | GroupType   |
|——————-|—————————-|————-|
| Marketing Team    | marketing@yourdomain.com   | Unified     |
| HR Updates        | hr-updates@yourdomain.com  | Unified     |

You can open this file in Excel to review and manage the group ownership list easily.

Additional Tips for Better Results

– Always make sure you are connected to Exchange Online PowerShell before running these commands.
– Use actual DistinguishedName in place of the placeholder if you want to avoid running two commands.
– You can further filter by group type or domain if needed.
– This script is handy during employee offboarding to quickly assess ownership impacts.

Conclusion

And that’s it! You now know how to pull a list of Microsoft 365 groups owned by a specific user using a simple PowerShell script. This is especially useful for audits, compliance, and day-to-day administration in any Microsoft 365 environment.

If you found this guide helpful, consider bookmarking it or sharing it with your fellow IT colleagues.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *