Jump to content
  • entries
    60
  • comments
    63
  • views
    780

When your teachers create their own class teams


How to add the pupils to existing empty teams with powershell

 

 

 

 

req: a sims report with the columns classcode, admission number, admission number in the office field of 365 accounts, class code in the team name of the format #:classcode#

 

 


#get useraccounts, drop in file
get-msoluser -all | where-object {$_.office} | Select-Object Userprincipalname,office | export-csv -path msoluser.csv -NoTypeInformation

#add useraccounts to lookup table
write-output "Adding pupils to lookup"
$xpupils = @{}
import-csv msoluser.csv | foreach {
   $xpupils.add($_.office,$_.userprincipalname)
   }

#fetch teams
write-output "Fetching teams"
$xteams = get-team | Select-Object groupid,displayname

#process teams
write-output "processing teams"
foreach ($xteam in $xteams)  
{

   $xgroupid = $xteam.groupid
   $xname = $xteam.displayname

   $xListofCodes = [regex]::match($xname,'#.*)#').Groups[1].Value

   if ($xListofCodes.length -gt 3){


       $xCodeArray = $xListofCodes -split ","
       Write-Output $xteam.groupid
       foreach ($xcode in $xCodeArray) {
               Write-Output $xcode
               #Write-Output $xcode    
               #make an array of admission numbers that are assigned to this code
               $xclassarray = @()    
               import-csv studentclasses.csv | foreach {
                   #check row classcode matches $xcode
                   if ($_.class -eq $xcode) {
                           #add to array
                           $xclassarray += $xpupils[$_.adno]
                           }

                   
                   



                    }
           #printarray
           foreach ($ad in $xclassarray) {
           
           
                   Write-Output $ad
                   
                   #add to team. 

                   Add-TeamUser -GroupID $xgroupid -user $ad
                   
                   }
           
           
           }
       
       
       
       }


}



Edited by browolf

0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...