List M365 Groups Created via Teams with Graph PowerShell [2025]

Microsoft 365 Groups created through Microsoft Teams are essential for collaboration across your organization, bringing together shared resources like emails, files, and calendars. Sometimes IT administrators may need to identify groups created via Teams to monitor activity or ensure governance. This article provides a PowerShell script to list all Microsoft 365 Groups created through Teams with details like Group Name, Email Address, Created Time, and Privacy.

The Script

# Ensure that the Microsoft Graph PowerShell module is installed and imported
# Install-Module -Name Microsoft.Graph -Force -AllowClobber
Import-Module Microsoft.Graph

# Connect to Microsoft Graph with the necessary permissions
Connect-MgGraph -Scopes "Group.Read.All"

# Fetch all M365 groups (Unified Groups) created via Teams
$groups = Get-MgGroup -All -Filter "resourceProvisioningOptions/any(x:x eq 'Team')" | 
    Select-Object DisplayName Mail CreatedDateTime Visibility

# Create a collection to store the results
$results = @()

# Loop through each group and store the relevant information
foreach ($group in $groups) {
    $results += [pscustomobject]@{
        'Group Name'   = $group.DisplayName
        'Mail'         = $group.Mail
        'Created Time' = $group.CreatedDateTime
        'Privacy'      = $group.Visibility
    }
}

# Display the results in tabular format
$results | Format-Table -AutoSize

# Optionally export to CSV
# $results | Export-Csv -Path "TeamsCreatedM365Groups.csv" -NoTypeInformation

Script Explanation

  • Connect to Microsoft Graph: The script imports the Microsoft Graph PowerShell module and connects to Microsoft Graph using Connect-MgGraph with the "Group.Read.All" permission scope, allowing the script to read all groups in the tenant.
  • Filter M365 Groups Created via Teams: Using the Get-MgGroup cmdlet with the filter resourceProvisioningOptions/any(x:x eq 'Team'), we retrieve only groups created through Teams.
  • Select Relevant Fields: The script fetches the group’s name, email, creation date, and privacy setting, storing them for further processing.
  • Output the Results: The results are displayed in a tabular format using Format-Table, or you can export the data to a CSV for further analysis.

Further Enhancements

  • Include More Properties: Add additional properties like Group ID, Owners, or Membership Type.
  • Filter by Date Range: Apply a filter on the CreatedDateTime field to display groups created within a specific timeframe.
  • Filter by Privacy Setting: You can modify the script to return only public or private groups by filtering the Visibility field.
  • Audit Group Activity: Integrate the script with Microsoft Graph’s reporting API to retrieve activity details like the last time the group was used.

Possible Errors & Solutions

Error Cause Solution
Insufficient Privileges Lack of required permissions to run the script. Ensure the account has the Group.Read.All permission and an administrator has granted consent.
Empty Results No groups created via Teams found. Ensure your tenant has M365 Groups created via Teams, or inspect the group’s resourceProvisioningOptions property.
Connection Issues Unable to connect to Microsoft Graph. Re-authenticate by running Disconnect-MgGraph and Connect-MgGraph again with the correct credentials.

Conclusion

This PowerShell script provides an easy way to list all Microsoft 365 Groups created via Microsoft Teams, showing useful details like group name, email, creation date, and privacy setting. This helps administrators monitor Teams-created groups efficiently and ensure proper governance. Feel free to modify or extend the script to suit your organization’s needs.

© m365corner.com. All Rights Reserved. Design by HTML Codex