Microsoft Teams is an essential collaboration tool for organizations, but as projects end or Teams become inactive, administrators may need to archive Teams to preserve their data. Archiving ensures the content remains accessible while preventing further activity.
In this article, we'll introduce a Graph PowerShell script that retrieves all archived Teams and displays them in a tabular format, making it easy for administrators to manage and review archived Teams.
# Connect to Microsoft Graph
Connect-MgGraph -Scopes "Group.Read.All" "TeamSettings.Read.All"
# Retrieve all Teams in the organization
$teams = Get-MgGroup -Filter "resourceProvisioningOptions/Any(x:x eq 'Team')" -All
# Create an array to store archived teams information
$archivedTeams = @()
# Loop through each team and check if it's archived
foreach ($team in $teams) {
$teamDetails = Get-MgTeam -TeamId $team.Id
if ($teamDetails.IsArchived -eq $true) {
# Store archived team details in a custom object
$archivedTeamInfo = [PSCustomObject]@{
TeamName = $team.DisplayName
TeamId = $team.Id
IsArchived = $teamDetails.IsArchived
}
$archivedTeams += $archivedTeamInfo
}
}
# Check if any archived teams are found and display the results
if ($archivedTeams.Count -gt 0) {
$archivedTeams | Format-Table TeamName TeamId IsArchived -AutoSize
} else {
Write-Output "No archived teams found."
}
# Disconnect from Microsoft Graph
Disconnect-MgGraph
Group.Read.All
and TeamSettings.Read.All
) to read group and Team settings.Get-MgTeam
cmdlet to retrieve the details of the Team. The key property IsArchived
is used to check if the Team has been archived.Format-Table
. If no archived Teams are found, the script outputs a message indicating so.$archivedTeams | Export-Csv -Path "C:\Path\To\ArchivedTeams.csv" -NoTypeInformation
Error | Cause | Solution |
Insufficient privileges to complete the operation. | The account used to run the script does not have sufficient permissions. | Ensure that the account has Group.Read.All and TeamSettings.Read.All permissions. You may need to re-authenticate with elevated privileges or contact your admin for access. |
No archived teams found. | The script could not find any Teams with the IsArchived status set to true. |
Verify that the Teams you're checking have been properly archived. If you believe there should be archived Teams, check the archiving status in the Microsoft Teams admin center. |
Get-MgTeam : Resource not found for the segment 'Team'. | The Team ID provided is invalid or cannot be accessed. | Ensure that the Team IDs are valid by using Get-MgGroup to list all Teams and confirm their IDs. |
Authorization_RequestDenied | The token used for authentication does not have the necessary permissions. | Use the Connect-MgGraph cmdlet with the appropriate scopes (Group.Read.All , TeamSettings.Read.All ) and reconnect. |
This script simplifies the process of retrieving all archived Microsoft Teams, displaying them in a clean, easy-to-read format. By leveraging Graph PowerShell, administrators can automate this task and enhance their reporting capabilities, ensuring that archived Teams are properly managed and preserved.
© m365corner.com. All Rights Reserved. Design by HTML Codex