-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathXLSImport-Team-Member.ps1
51 lines (39 loc) · 1.42 KB
/
XLSImport-Team-Member.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
Import-Module MicrosoftTeams
$account = Get-Credential
Connect-MicrosoftTeams -Credential $account
$excel = New-Object -Com Excel.Application
$sheet = $excel.Workbooks.Open("C:\Users\Manuel Ruiz\OneDrive - Colegio Bautista Cristiano\PowerShell Teams\Excel\transactions.xlsx").Sheets.Item(1)
$startRow = 2
$lastRow = 128
for ($i = $startRow; $i -le $lastRow; $i++) {
# Inicianlizando variables
$group_id = ''
$account_name = ''
# Segunda columna: ID del Team
if ($sheet.Cells.Item($i, 2).Text -ne '') {
$group_id = $sheet.Cells.Item($i, 2).Text
}
else {
Write-Output "Falta el ID del grupo en la linea $($i). Deteniendo la ejecución."
break
}
# Quinta columna: Cuenta del estudiante
if ($sheet.Cells.Item($i, 5).Text -ne '') {
$account_name = $sheet.Cells.Item($i, 5).Text
}
else {
Write-Output "Falta la cuenta del estudiante en la linea $($i). Deteniendo la ejecución"
break
}
if ($account_name -ne '') {
if ($group_id -ne '') {
Write-Output "Insertando el estudiante con cuenta $($account_name) al team $($group_id)"
Add-TeamUser -GroupId $group_id -User $account_name -Role Member
}
}
# Pausar el programa por 1 segundo
# Start-Sleep -Seconds 0.5
}
Write-Output "Estudiantes insertados exitosamente a los Teams"
Disconnect-MicrosoftTeams
$excel.Workbooks.Close()