-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path02-AddStudentsToChannels.ps1
93 lines (82 loc) · 3.5 KB
/
02-AddStudentsToChannels.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# =============================================================================
# TEAMS FÜR PRÜFUNGEN
# Montessori-Schule Aufkirchen
# https://github.com/aessing/montessori-aufkirchen
# -----------------------------------------------------------------------------
# Developer.......: Andre Essing (https://www.andre-essing.de/)
# (https://github.com/aessing)
# (https://twitter.com/aessing)
# (https://www.linkedin.com/in/aessing/)
# -----------------------------------------------------------------------------
# THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
# EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
# =============================================================================
[CmdletBinding()]
param (
[Parameter(Mandatory=$true)]
[string]$Name,
[Parameter(Mandatory=$true)]
[string]$SchuelerCSV
)
Import-Module MicrosoftTeams -RequiredVersion "5.1.0"
###############################################################################
#
# Ausgabe eines Header
#
Write-Host ""
Write-Host ""
Write-Host "==============================================================================="
Write-Host "| SchülerInnen werden zu Ihren Kanälen hinzugefügt"
Write-Host "| " -NoNewline
Write-Host "Zugriff wird erlaubt" -ForegroundColor Green
Write-Host "|"
Write-Host "| Team Name: " -NoNewline
Write-Host $Name -ForegroundColor Cyan
Write-Host "| Schüler CSV-Datei: " -NoNewline
Write-Host $SchuelerCSV -ForegroundColor Cyan
Write-Host "==============================================================================="
###############################################################################
#
# Login
#
Write-Host ""
Write-Host " - Anmeldung bei Teams " -NoNewline
Write-Host "(Anmeldung im Browser)" -ForegroundColor Yellow
Connect-MicrosoftTeams | Out-Null
###############################################################################
#
# Füge SchülerInnen als Member zu jedem Kanal hinzu
#
$GroupId = Get-Team -DisplayName $Name.Trim() | Where-Object Displayname -eq $Name.Trim()
Get-TeamChannel -GroupId $GroupId.GroupId -MembershipType Private | ForEach-Object {
$TeamChannel = $_
$TeamChannelName = $TeamChannel.DisplayName
$TeamChannelName = $TeamChannelName.Trim()
Write-Host ""
Write-Host " - Füge SchülerInnen zum Kanal hinzu: " -NoNewline
Write-Host $TeamChannelName -ForegroundColor Cyan
Import-Csv -Path $SchuelerCSV | ForEach-Object{
$Student = $_
$StudentName = $Student.upn
$StudentName = $StudentName.Trim()
if ($Student.channel -eq $TeamChannelName) {
Write-Host " - SchülerIn: " -NoNewline
Write-Host $StudentName -ForegroundColor Cyan
$MemberExist = Get-TeamChannelUser -GroupId $GroupId.GroupId -DisplayName $TeamChannelName | Where-Object {$_.User -eq $StudentName}
if ( -not $MemberExist ) {
Add-TeamChannelUser -GroupId $GroupId.GroupId -DisplayName $TeamChannelName -User $_.upn
}
}
}
}
###############################################################################
#
# Fertig
#
Write-Host ""
Write-Host " - fertig!"
Write-Host ""
Write-Host ""
###############################################################################
# EOF