-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathCreateUserAccounts.ps1
More file actions
45 lines (39 loc) · 1.82 KB
/
Copy pathCreateUserAccounts.ps1
File metadata and controls
45 lines (39 loc) · 1.82 KB
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
#Import Active Directory Module
Import-module activedirectory
#Autopopulate Domain
$dnsDomain = $env:userdnsdomain
$split = $dnsDomain.split(".")
$domain = $null
foreach ($part in $split) {
if ($null -ne $domain) {
$domain += ","
}
$domain += "DC=$part"
}
#Declare any Variables
$dirpath = $pwd.path
$counter = 0
#import CSV File
$ImportFile = Import-csv "$dirpath\ADUsers.csv"
$TotalImports = $importFile.Count
#Create Users
$ImportFile | ForEach-Object {
$counter++
$progress = [int]($counter / $totalImports * 100)
Write-Progress -Activity "Provisioning User Accounts" -status "Provisioning account $counter of $TotalImports" -perc $progress
if ($_.Manager -eq "") {
New-ADUser -SamAccountName $_."SamAccountName" -Name $_."Name" -Surname $_."Surname" -GivenName $_."GivenName" -AccountPassword (ConvertTo-SecureString $_."Password" -AsPlainText -Force) -Enabled $true -title $_."title" -officePhone $_."officePhone" -department $_."department" -emailaddress $_."Email" -Description $_."title"
}
else {
New-ADUser -SamAccountName $_."SamAccountName" -Name $_."Name" -Surname $_."Surname" -GivenName $_."GivenName" -AccountPassword (ConvertTo-SecureString $_."Password" -AsPlainText -Force) -Enabled $true -title $_."title" -officePhone $_."officePhone" -department $_."department" -emailaddress $_."Email" -Description $_."title" -Manager $_."Manager"
}
$userImagePath = Join-Path -Path $dirpath -ChildPath "userimages\$($_.name).jpg"
$defaultImagePath = Join-Path -Path $dirpath -ChildPath "userimages\user.jpg"
if (Test-Path -Path $userImagePath) {
$photo = [System.IO.File]::ReadAllBytes($userImagePath)
}
else {
$photo = [System.IO.File]::ReadAllBytes($defaultImagePath)
}
Set-ADUser $_.samAccountName -Replace @{thumbnailPhoto = $photo }
}