-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBulkuserimport.ps1
More file actions
46 lines (38 loc) · 1.5 KB
/
Copy pathBulkuserimport.ps1
File metadata and controls
46 lines (38 loc) · 1.5 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
46
# Import active directory module for running AD cmdlets
Import-Module activedirectory
#Store the data from ADUsers.csv in the $ADUsers variable
$ADUsers = Import-csv C:\scripts\associates.csv
#Loop through each row containing user details in the CSV file
foreach ($User in $ADUsers)
{
#Read user data from each field in each row and assign the data to a variable as below
$SAM = $User.SAM
$UPN = $User.UPN
$Firstname = $User.firstname
#$Initials = $User.initial
$Lastname = $User.lastname
$OU = $User.ou #This field refers to the OU the user account is to be created in
$Password = $User.password
$ErrorActionPreference = "SilentlyContinue"
#Check to see if the user already exists in AD
#if (Get-ADUser -F {SamAccountName -eq $SAM})
#{
#If $SAM does exist, give a warning
#Write-Warning "A user account with username $SAM already exist in Active Directory."
#}
#else
#{
#User does not exist then proceed to create the new user account
#Account will be created in the OU provided by the $OU variable read from the CSV file
New-ADUser `
-Name "$Firstname $Lastname" `
-SamAccountName $SAM `
-UserPrincipalName "[email protected]" `
-GivenName $Firstname `
-Surname $Lastname `
-Enabled $True `
-Path $OU `
-PasswordNeverExpires $true `
-AccountPassword (convertto-securestring $Password -AsPlainText -Force)
#}
}