Want to archive teams in bulk

%3CLINGO-SUB%20id%3D%22lingo-sub-2148517%22%20slang%3D%22en-US%22%3EWant%20to%20archive%20teams%20in%20bulk%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2148517%22%20slang%3D%22en-US%22%3E%3CP%3EI%20want%20to%20archive%20teams%20in%20bulk%20with%20the%20id.%20i%20am%20sharing%20my%20script.%20but%20it%20is%20not%20happening.%20I%20am%20sharing%20my%20script.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%24a%20%3D%20Import-Csv%20C%3A%5CUsers%5Cparveen.kumar%5CDesktop%5Ca.csv%3C%2FP%3E%3CP%3Eforeach%20(%24a%20in%20%24data)%20%7B%24GroupID%20%3D%20(Set-TeamArchivedState%20-GroupId%20%24a%20.id%20-Archived%20%24a.Archive).GroupID%20%7D%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20csv%20file%20is%20here%3A%3C%2FP%3E%3CP%3Eid%2CdisplayName%2CArchive%3CBR%20%2F%3E03fe83c7-cc3e-403e-bbd3-18f1f7efef42%2Ctest%20for%20new%20aca%2CTRUE%3CBR%20%2F%3Ee550eefc-1689-4530-8112-085e6fba1c8c%2CVIB%2CTRUE%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2148517%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EWindows%20PowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2149071%22%20slang%3D%22en-US%22%3ERe%3A%20Want%20to%20archive%20teams%20in%20bulk%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2149071%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F889347%22%20target%3D%22_blank%22%3E%40parveenprajapati%3C%2FA%3E%26nbsp%3BSet-TeamArchivedState's%20-Archived%20parameter%20expects%20a%20boolean%20value%2C%20so%20would%20need%20to%20be%20called%20as%20%22-Archived%3A%24true%22%20(or%20%24false).%20The%20easiest%20way%20round%20this%20is%20to%20just%20put%20the%20teams%20you%20want%20to%20archive%20in%20the%20CSV.%20You've%20also%20got%20an%20error%20in%20the%20foreach%20where%20data%20never%20gets%20anything%20assigned%20to%20it.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'd%20have%20thought%20the%20below%20would%20work%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%24csv%20%3D%20Import-Csv%20C%3A%5CUsers%5Cparveen.kumar%5CDesktop%5Ca.csv%0Aforeach%20(%24team%20in%20%24csv)%20%7B%0A%20%20%20%20Set-TeamArchivedState%20-GroupId%20%24team.id%20-Archived%3A%24true%0A%7D%0A%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2151154%22%20slang%3D%22en-US%22%3ERe%3A%20Want%20to%20archive%20teams%20in%20bulk%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2151154%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F942392%22%20target%3D%22_blank%22%3E%40CoasterKaty%3C%2FA%3E%26nbsp%3BThanks%20Katy%2C%20the%20script%20is%20working%20fine.%20I%20have%20an%20another%20query.%20I%20have%20more%20then%202400%20teams%20and%20for%20my%20school%20and%26nbsp%3B%20I%20want%20to%20archive%20teams%20time%20to%20time%20in%20the%20end%20of%20the%20session%20with%20keyword%20like%20'2020'%2C%20'Class-VI-A'%2C%20'ICT'%2C%20'PA'.%20Is%20there%20any%20possibility%20in%20PowerShell%20to%20archive%20with%20keywords.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2152376%22%20slang%3D%22en-US%22%3ERe%3A%20Want%20to%20archive%20teams%20in%20bulk%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2152376%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F889347%22%20target%3D%22_blank%22%3E%40parveenprajapati%3C%2FA%3E%26nbsp%3BYou%20could%20do%20something%20like%3A%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3EGet-Team%20%7C%20Where%20%7B%24_.DisplayName%20-like%20%22*2020*%22%20%7C%20Set-TeamArchivedState%20-Archived%3A%24true%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3Ealthough%20if%20you're%20using%20Teams%20for%20school%20classes%20I'd%20recommend%20looking%20at%20School%20Data%20Sync%20for%20next%20year%20as%20it%20handles%20the%20creation%2Fupdate%2Farchival%20of%20teams%20for%20you.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
New 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:

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

4 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.