-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMigrate-Teacher.ps1
83 lines (67 loc) · 2.67 KB
/
Migrate-Teacher.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
function Start-TeacherMigration
{
<#
.Synopsis
Creates teachers in Microsoft Teams.
.Description
Reads ASV Data from Get-DataFromAsvXml and creates teacher user accounts based on ASV Data.
.Parameter data
Object returned from Get-DataFromAsvXml
.Parameter AADUserOutput
Path where output file of created users sould be stored.
.Parameter Suffix
Suffix after @ in UPN firstname.lastname@SUFFIX (somedomain.tld)
.Parameter ExemptListPath
Path to .csv file with teachers not to create. Structure (vorname,nachname)
.Parameter WhatIf
Does not create users in production system. Only prints users to console and creates output file.
.Example
# Creates students in asv.
Start-TeacherMigration -data $data -AADUserOutput C:\users\docuemtns\created-teachers.csv -Suffix myschool.tld
#>
param
(
[parameter(Mandatory = $true)] $data,
[parameter(Mandatory = $true)] $AADUserOutput,
[parameter(Mandatory = $true)] $Format,
$WhatIf = $false,
$ExemptListPath
)
if(!($ExemptListPath -eq $null))
{
$ExemptList = Get-ExemptList -extemptListPath $ExemptListPath
} else {
$ExemptList = @()
}
$aadusers = Get-AadUserHashTable
$outs = @()
$PasswordProfile = New-Object -TypeName Microsoft.Open.AzureAD.Model.PasswordProfile
$PasswordProfile.ForceChangePasswordNextLogin = $true
$LicensesToAssign = Get-LicensesToAssign -Plans @('M365EDU_A3_FACULTY')
foreach ($l in $data.Lehrer)
{
$upn = Get-Upn -vorname $l.Vorname -nachname $l.Familienname -format $Format
$pass = (Get-RandomPassword(12).ToString()) + "!"
$PasswordProfile.Password = $pass
if (! ($ExemptList.Contains($upn) -or $aadusers.ContainsKey($upn)) )
{
if(!$WhatIf)
{
$aad = New-AzureADUser -DisplayName ("$($l.Vorname) $($l.Familienname)") -GivenName ($l.Vorname) -Surname ($l.Familienname) -MailNickName ($upn.Split("@")[0]) -UserPrincipalName $upn -PasswordProfile $PasswordProfile -AccountEnabled $true -UsageLocation DE
Set-AzureADUserLicense -ObjectId $aad.ObjectId -AssignedLicenses $LicensesToAssign
}
else
{
Write-Host "[WHATIF] Would create $upn"
}
$out = New-Object PSObject
$out | Add-Member -MemberType NoteProperty -Name UPN -Value $upn
$out | Add-Member -MemberType NoteProperty -Name Nachname -Value $l.Familienname
$out | Add-Member -MemberType NoteProperty -Name Vorname -Value $l.Vorname
$out | Add-Member -MemberType NoteProperty -Name Pass -Value $pass
$outs += $out
}
}
$outs | Export-Csv -Path $AADUserOutput -Encoding UTF8
return
}