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.
# 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
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:
Here are some potential enhancements you can consider adding to the script:
$teamData | Export-Csv -Path "TeamsCreationData.csv" -NoTypeInformation
$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
$teamData | Sort-Object CreatedTime | Format-Table -AutoSize
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.
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.
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).
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.
© m365corner.com. All Rights Reserved. Design by HTML Codex