Want to archive teams in bulk

Copper Contributor

I want to archive teams in bulk with the id. i am sharing my script. but it is not happening. I am sharing my script. 


$a = Import-Csv C:\Users\parveen.kumar\Desktop\a.csv

foreach ($a in $data) {$GroupID = (Set-TeamArchivedState -GroupId $a .id -Archived $a.Archive).GroupID }


The csv file is here:

03fe83c7-cc3e-403e-bbd3-18f1f7efef42,test for new aca,TRUE

5 Replies

@parveenprajapati Set-TeamArchivedState's -Archived parameter expects a boolean value, so would need to be called as "-Archived:$true" (or $false). The easiest way round this is to just put the teams you want to archive in the CSV. You've also got an error in the foreach where data never gets anything assigned to it.


I'd have thought the below would work:


$csv = Import-Csv C:\Users\parveen.kumar\Desktop\a.csv
foreach ($team in $csv) {
    Set-TeamArchivedState -GroupId $team.id -Archived:$true


@CoasterKaty Thanks Katy, the script is working fine. I have an another query. I have more then 2400 teams and for my school and  I want to archive teams time to time in the end of the session with keyword like '2020', 'Class-VI-A', 'ICT', 'PA'. Is there any possibility in PowerShell to archive with keywords.

@parveenprajapati You could do something like:

Get-Team | Where {$_.DisplayName -like "*2020*" | Set-TeamArchivedState -Archived:$true

although if you're using Teams for school classes I'd recommend looking at School Data Sync for next year as it handles the creation/update/archival of teams for you. 

@CoasterKaty Thank you for your help. Its working now.


You can use this script: https://m365scripts.com/microsoft-teams/how-to-archive-team-in-microsoft-teams/#archive-teams-in-bul...

In this script, you can directly use the teams' name instead of id in the CSV file.