Forum Discussion

parveenprajapati's avatar
parveenprajapati
Copper Contributor
Feb 19, 2021

Want to archive teams in bulk

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:

id,displayName,Archive
03fe83c7-cc3e-403e-bbd3-18f1f7efef42,test for new aca,TRUE
e550eefc-1689-4530-8112-085e6fba1c8c,VIB,TRUE 

  • 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
    }
    

     

    • parveenprajapati's avatar
      parveenprajapati
      Copper Contributor

      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.

      • CoasterKaty's avatar
        CoasterKaty
        MVP

        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. 

Resources