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.
# 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
Connect-MgGraph
with the "Group.Read.All" permission scope, allowing the script to read all groups in the tenant.Get-MgGroup
cmdlet with the filter resourceProvisioningOptions/any(x:x eq 'Team')
, we retrieve only groups created through Teams.Format-Table
, or you can export the data to a CSV for further analysis.CreatedDateTime
field to display groups created within a specific timeframe.Visibility
field.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. |
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