-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreateADUsers.ps1
81 lines (74 loc) · 3.08 KB
/
CreateADUsers.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
# This script is for adding users to an Active directory. Modify however you wish. The current values are based off a domain called galfed.com.
# Create destination AD Structures
New-ADOrganizationalUnit -name "GF-Accounts" -path "DC=galfed,DC=com"
New-ADOrganizationalUnit -name "Users" -path "OU=GF-Accounts,DC=galfed,DC=com"
New-ADOrganizationalUnit -name "Admins" -path "OU=GF-Accounts,DC=galfed,DC=com"
New-ADOrganizationalUnit -name "GF-Groups" -path "DC=galfed,DC=com"
# Set custom parent AD Paths variables
$useracctpath = "OU=Users,OU=GF-Accounts,DC=galfed,DC=com"
$adminacctpath = "OU=Admins,OU=GF-Accounts,DC=galfed,DC=com"
$grouphomepath = "OU=GF-Groups,DC=galfed,DC=com"
# Creatr catchall group for Similar occupations
New-ADGroup -Name "IT support" -GroupScope Global -Path $grouphomepath
New-ADGroup -Name "Executive" -GroupScope Global -Path $grouphomepath
# Grab user data
$UserImport = Import-CSV c:\Users\Administrator\Desktop\SetupScripts\GFUsers.csv
# Loop through users and create accounts and set group memberships.
$UserImport | ForEach-Object {
$givenname = $_.Firstname
$initial = $_.MiddleInitial
$surname = $_.LastName
$fullname = $_.FirstName + " " + $_.MiddleInitial + " " + $_.LastName
$samname = $_.FirstName + "." + $_.LastName
$email = $samname + "@galfed.com"
$pass = $_.LastName + "Pass"
$password = (ConvertTo-SecureString $pass -AsPlainText -Force)
$group = $_.Occupation
New-ADuser `
-GivenName $givenname `
-Initials $initial `
-Surname $surname `
-Name $fullname `
-Path $useracctpath `
-SamAccountName $samname `
-EmailAddress $email `
-AccountPassword $password `
-ChangePasswordAtLogon $false `
-PasswordNeverExpires $true `
-Enabled $true `
-Office $group `
-Company "Galactic Federation" `
-DisplayName $fullname `
-Verbose
# Check if System Admin, if so create second account for domain admin use.
if ($_.Occupation -eq "Quantium Tech"){
# Create Domain Admin account - format First.Last.admin
$adminsam = $samname + ".adm"
$newpass = $_.LastName + "Admin"
$adminpass = (ConvertTo-SecureString $newpass -AsPlainText -Force)
New-ADuser `
-Name $fullname `
-Path $adminacctpath `
-SamAccountName $adminsam `
-AccountPassword $adminpass `
-ChangePasswordAtLogon $false `
-PasswordNeverExpires $true `
-Enabled $true `
-Description $group `
-Company "Galactic Federation" `
-DisplayName $fullname `
-Verbose
Add-ADGroupMember "Domain Admins" $adminsam -Verbose
Add-ADGroupMember "Enterprise Admins" $adminsam -Verbose
Add-ADGroupMember "IT support" $samname -Verbose
}
ElseIf ($_.Occupation -like "Galactic Ambassador"){
Add-ADGroupMember "Executive" $samname -Verbose
}
ElseIf (-not (Get-ADGroup -Filter "Name -eq '$group'" -ErrorAction SilentlyContinue)){
New-ADGroup -Name "$group" -GroupScope Global -Path $grouphomepath
Add-ADGroupMember "$group" $samname -Verbose
} else {
Add-ADgroupMember "$group" $samname -Verbose
}
}