Skip to content

Instantly share code, notes, and snippets.

@wongcyrus
Last active September 1, 2020 02:34
Show Gist options
  • Save wongcyrus/d0a4141f1a0cd0710da83b954be1f653 to your computer and use it in GitHub Desktop.
Save wongcyrus/d0a4141f1a0cd0710da83b954be1f653 to your computer and use it in GitHub Desktop.
Batch imports student to Microsoft Team
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
set-executionpolicy remotesigned
Install-Module MicrosoftTeams
Import-Module MicrosoftTeams
Disconnect-MicrosoftTeams
$User = "t-cywong@stu.vtc.edu.hk"
$Password = ""
$ClassListFolder="C:\Users\developer\Documents\WindowsPowerShell\"
# ITP4104-Cloud Services-2021-2-A-cywong.csv with just one column.
#email
#student@stu.vtc.edu.hk
$PWord = ConvertTo-SecureString -String $Password -AsPlainText -Force
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $PWord
Connect-MicrosoftTeams -Credential $Credential
Get-ChildItem $ClassListFolder -Filter *.csv |
Foreach-Object {
Write-Output $_.Name
$groupId = New-Team -DisplayName $_.FullName
Import-Csv -Path $studentPath | foreach{Add-TeamUser -GroupId $groupId.GroupId -User $_.email -Role Member}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment