Track Microsoft Teams Creation Date

As Microsoft Teams becomes an integral part of organizational collaboration, tracking and managing the creation of Teams is vital for IT administrators. Knowing when a team was created can provide insights into its usage, relevance, and lifecycle management.

In this article, we’ll explore a Graph PowerShell script that queries Microsoft Teams and outputs the creation date/time along with the Team Name, Description, and Team Type in a tabular format. This script will help you effectively monitor the creation and management of Teams in your organization.


The Script

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

# Fetch all teams
$teams = Get-MgGroup -Filter "resourceProvisioningOptions/Any(x:x eq 'Team')" -Property Id, DisplayName, Description, Visibility, CreatedDateTime -All

# Prepare an array to store the team data
$teamData = @()

foreach ($team in $teams) {
    # Determine the team type based on visibility
    $teamType = if ($team.Visibility -eq "Public") { "Public" } else { "Private" }

    # Add the team's information to the array
    $teamData += [pscustomobject]@{
        TeamName    = $team.DisplayName
        Description = $team.Description
        TeamType    = $teamType
        CreatedTime = $team.CreatedDateTime
    }
}

# Output the data in a table format
$teamData | Format-Table -AutoSize

How the Script Works

This script efficiently retrieves and sorts Microsoft Teams based on their creation date and time. Below is a step-by-step explanation of how the script operates:

  1. Connecting to Microsoft Graph: The script begins by connecting to Microsoft Graph using the Connect-MgGraph cmdlet. The required scopes (Team.ReadBasic.All and Group.Read.All) allow the script to read basic information about Teams and group member data.
  2. Fetching Teams: The Get-MgGroup cmdlet is used to retrieve all groups that have a Team resource provisioning option, ensuring only Microsoft Teams groups are fetched. The script also retrieves essential properties like the team’s ID, DisplayName, Description, Visibility, and CreatedDateTime.
  3. Determining Team Type: The script checks the Visibility property to determine whether a team is Public or Private. Public teams are open to anyone in the organization, while Private teams are restricted to specific members.
  4. Storing and Displaying Data: For each team, the script stores the Team Name, Description, Team Type, and Created Time in a PowerShell custom object. This data is then output in a neatly formatted table using the Format-Table cmdlet.
Graph PowerShell script output displaying Microsoft Teams with their creation dates, names, descriptions, and types

Further Enhancements

Here are some potential enhancements you can consider adding to the script:

  • Exporting Data to CSV: To create a record of the Teams’ creation dates, you can export the output to a CSV file. Replace the Format-Table cmdlet with the following:
    $teamData | Export-Csv -Path "TeamsCreationData.csv" -NoTypeInformation
  • Filtering by Date Range: If you’re interested in teams created within a specific time frame, you can add a filter to the script. For example, to find teams created after January 1, 2023:
    $teams = Get-MgGroup -Filter "resourceProvisioningOptions/Any(x:x eq 'Team') and CreatedDateTime ge 2023-01-01T00:00:00Z" -Property Id, DisplayName, Description, Visibility, CreatedDateTime -All
  • Including More Properties: You can extend the script to include additional properties such as MailNickname, Classification, or Owners. This could provide more context about each team and its usage.
  • Sorting by Creation Date: To identify the oldest or newest teams, you can sort the output by the creation date:
    $teamData | Sort-Object CreatedTime | Format-Table -AutoSize

Possible Errors & Solutions

Insufficient Permissions

Cause: If the script fails to retrieve team data, it might be due to insufficient permissions.

Solution: Ensure that your account has the necessary permissions (Team.ReadBasic.All and Group.Read.All). You might need to re-authenticate or request additional permissions.

No Teams Found

Cause: If the script does not return any teams, it could be due to a filtering issue or the absence of teams in your tenant.

Solution: Verify the filtering criteria in the Get-MgGroup cmdlet. Remove the filter temporarily to see if any groups are returned without filtering.

Incorrect Date Format

Cause: When filtering by date, an incorrect date format might result in an error.

Solution: Ensure that the date is in the correct ISO 8601 format (YYYY-MM-DDTHH:MM).


Conclusion

This Graph PowerShell script is a powerful tool for IT administrators to monitor and manage the creation of Microsoft Teams within their organization. By providing key details such as Team Name, Description, Team Type, and Created Time, the script offers valuable insights into the lifecycle and management of Teams. With potential enhancements like exporting data or filtering by date range, this script can be customized to meet the specific needs of your organization.

Leveraging Microsoft Graph and PowerShell, you can streamline the management of Microsoft Teams and ensure that your collaboration environment remains organized and efficient.

Suggested Reading

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