Hi, I'm trying to get a script that creates Active Directory users in bulk from a .csv file to work. Here is what I have so far. I'm getting an unexpected token error. I have changed the domain in line 23 and 35. Any help would be great.
1 # Import list of Users From CSV into $Userlist
2
3 $UserList=IMPORT-CSV C:\Windows\LTSVC\BulkADAccounts.csv
4
5 # Step through Each Item in the List
6
7 FOREACH ($Person in $UserList) {
8
9 # Build Username
10
11 $Username=$Person.Username
12
13 # Build Password from Firstname and Lastname
14
15 $Password=$Person.Firstname+$Person.Lastname
16
17 # Build the Displayname
18
19 $Name=$Person.Firstname+” “+$Person.Lastname
20
21 # Build and define Domain name
22
23 $Domain="@xxxxxxx"
24
25 # Build User Principal Name
26
27 $UPN=$Username+$Domain
28
29 # Build and define Home Directory path
30
31 $HDrive="\\file1\d$\homedirs\test"
32
33 # Build and define which Organizational Unit to create User inside
34
35 $OU="OU=TEST,DC=xxxxxx.local,DC=com"
36
37 # Create Account in Active Directory
38
39 New-ADUser -Name $Name –GivenName $Person.Firstname –Surname $Person.Lastname –DisplayName $Name –SamAccountName $Username -HomeDrive "H:" -HomeDirectory $HDrive –UserPrincipalName $UPN -Path $OU
40
41 # Set Password
42
43 Set-ADAccountPassword -Identity $Username -NewPassword (ConvertTo-SecureString -AsPlainText $Password -Force)
44
45 # Add User to Security Groups
46
47 Add-ADPrincipalGroupMembership -Identity $Username -MemberOf "security group a","security group b"
48
49 # Enable Account
50
51 Enable-ADAccount -Identity $Username
52
53 }