🔧 New: User Management Graph PowerShell Toolkit

Simplify user tasks like bulk creation, updates, password resets, deletions, license checks & more — all from one place.

🚀 Launch Toolkit

List Microsoft Teams Created in the Last 30 Days Using Graph PowerShell

Monitoring recently created Microsoft Teams can help administrators track changes, enforce naming conventions, or spot unexpected activity. With Microsoft Graph PowerShell, you can easily fetch Teams created in the last 30 days—along with details like team name, description, owner, and type.


The Script

# Connect to Microsoft Graph with necessary permissions

Connect-MgGraph -Scopes "Group.Read.All", "User.Read.All", "Directory.Read.All"

# Set threshold date
$thresholdDate = (Get-Date).AddDays(-30)

# Prepare results array
$recentTeams = @()

# Proper Graph API endpoint
$uri = "https://graph.microsoft.com/v1.0/groups?`$filter=resourceProvisioningOptions/Any(x:x eq 'Team')&`$select=id,displayName,description,createdDateTime"

# Loop for pagination
do {
    try {
        $response = Invoke-MgGraphRequest -Uri $uri -Method GET
        $teams = $response.value

        foreach ($group in $teams) {
            try {
                if ($group.createdDateTime) {
                    $created = [datetime]$group.createdDateTime
                    if ($created -ge $thresholdDate) {
                        # Fetch team owner
                        $ownerUri = "https://graph.microsoft.com/v1.0/groups/$($group.id)/owners?`$select=displayName,userPrincipalName"
                        $ownerResponse = Invoke-MgGraphRequest -Uri $ownerUri -Method GET
                        $owner = $ownerResponse.value | Select-Object -First 1

                        # Add to results
                        $recentTeams += [PSCustomObject]@{
                            "Team Name"        = $group.displayName
                            "Team Description" = if ($group.description) { $group.description } else { "N/A" }
                            "Team Owner"       = if ($owner) { "$($owner.displayName) <$($owner.userPrincipalName)>" } else { "N/A" }
                            "Team Type"        = "Microsoft Team"
                        }
                    }
                } else {
                    Write-Warning "Group '$($group.displayName)' has no creation date."
                }
            } catch {
                Write-Warning "Error processing group '$($group.displayName)': $_"
            }
        }

        $uri = $response.'@odata.nextLink'
    } catch {
        Write-Warning "Error retrieving teams: $_"
        break
    }
} while ($uri)

# Output result
if ($recentTeams.Count -eq 0) {
    Write-Host "No Microsoft Teams created in the last 30 days were found." -ForegroundColor Yellow
} else {
    $recentTeams | Format-Table -AutoSize
}
                            

How the Script Works

Let's break it down step-by-step:

  1. Connection to Graph
  2. The script connects to Microsoft Graph with permissions to read group and user data.

  3. Set the Creation Threshold
  4. The thresholdDate is set to 30 days before the current date.

  5. Retrieves All Microsoft Teams
  6. Using Invoke-MgGraphRequest, the script fetches only Teams by filtering resourceProvisioningOptions.

  7. Filters by Creation Date
  8. Each team's createdDateTime is compared with the threshold date to determine if it was created recently.

  9. Fetches Owners for Each Team
  10. For each qualifying team, the script fetches one of its owners (name and email).

  11. Outputs Clean Table
  12. The result is displayed in the console in a tabular format with key headers.


Further Enhancing the Script

You can build on this script in several ways:

  • Export to CSV:
  • Add | Export-Csv "RecentTeams.csv" -NoTypeInformation to save the output.
  • Show All Owners: Instead of the first owner, loop through all owner objects for each team.
  • Email Notifications: Send the output to your email using Send-MailMessage.
  • Additional Filters:Filter teams by naming convention or presence of specific owners.

Possible Errors & Solutions

Error Cause Solution
403 Forbidden Missing permission scopes Ensure the user has Group.Read.All, Directory.Read.All, and User.Read.All permissions.
Cannot convert null to type "System.DateTime" Some groups have null createdDateTime Script handles this using a try block and skips such entries.
Unexpected token '??' You're using PowerShell 5.1 Use if () { } else { } instead of ??, which is only supported in PowerShell 7+.

Conclusion

This script provides a powerful way to track newly created Microsoft Teams in your environment. It's helpful for auditing, onboarding, or compliance monitoring. With a few enhancements, you can extend it into a complete reporting solution for Teams management.


Graph PowerShell Explorer Widget

20 Graph PowerShell cmdlets with easily accessible "working" examples.


Permission Required

Example:


                


                


                

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