-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImportADUsers.ps1
53 lines (45 loc) · 1.12 KB
/
ImportADUsers.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
#.csv for import needs the following fields:
#lastname;firstname;firm;phone
#Path to csv and delimiter
$Import = Import-Csv -Delimiter ";" -LiteralPath "list.csv"
#Where should the users be added?
$OU = "OU=Jitsi,DC=loechel,DC=sul"
#Count the number of entries
$i = 0
Foreach ($user in $Import)
{
#Check if the user is a company
if ( $user.firm )
{
#Check if the company has a contact person
if ( $user.firstname ){
$displayname = $user.firm + " - " + $user.firstname + " " + $user.lastname
$firstname = $user.firstname
$lastname = $user.lastname
}
#Company has no contact person
else{
$displayname = $user.firm
$firstname = " "
$lastname = " "
}
}
#User is not a company
else{
$displayname = $user.firstname + " " + $user.lastname
$firstname = $user.firstname
$lastname = $user.lastname
}
#Add to ActiveDirectory
New-ADObject -name $displayname -Type Contact -path $OU -OtherAttributes @{
'telephoneNumber' = $user.phone;
'givenName'= $firstname;
'sn'= $lastname;
'displayname'= $displayname
}
#Count iterations
$i++
#Write log
Write-Output $i
Write-Output $displayname
}