Friday, January 4, 2019

Create Active Directory LAB Users using PowerShell Script

Creating users for lab purposes is time consuming. 

There are different scripts online where you can automate this process. I have used a script found on this blog. This will create 300 unique accounts. 

First of all in order to be able to run PowerShell script on our Domain Controller, we need to apply the cmdlet Set-ExecutionPolicy RemoteSigned


We will add the script (*.ps1 file) on the C:\ Drive (root folder), so we can simply run it using ./CreateLabUsers.ps1

Once we run the script, it will prompt us for the CSV file. 



After loading it, we can see all the accounts being created



Now we will open the AD Users and Computers Tool


The users are created under the ExchangeUsers OU. 






On some labs we need additional information, for example Telephone Number. 

My PowerShell skills are very limited, so I will try to use the dsadd cmd. 

First of all lets check the information of the CSV file we have downloaded. The file contains FirstName, LastName, samAccountName, DisplayName and Password. 



Let's see what the dsadd can offer and what are the options. The structure is quite simple, we specify an option and then a name.  



We will add those users on a different OU. Actually we will delete all the previous users, since the new ones will have the same sAMAccountName, and the user creation would fail.  






We will run the cmd below:

dsadd user "cn=CallManager-User,ou=Telecoms,dc=theo,dc=local" -fn CallManager -ln User -display "CallManager User" -upn CallManager-User@theo.local -pwd Password1 -mustchpwd no -tel 02088881000 -iptel 1000 -mobile 07777771000


We can confirm that a new user is created under the OU we created earlier. 




We will open the CSV file using Google Sheets. We will add a new column that contains the user's Directory Number (DN) and then we will use the concatenate function to merge different information together. It is complicated, it is messy, but I created the whole script in less than 2 minutes. 

=CONCATENATE
("dsadd user cn=",C2,",OU=Telecoms,dc=theo,dc=local -fn ",A2," -ln ",B2,
-display  ",C2," -upn ",C2,"@theo.local -pwd ",E2,
" -mustchpwd no -tel 0208888",F2," -iptel ",F2," -mobile 0777777",F2)



We will auto-fill the whole G column. 




I have used additional fields, such as title, department etc. You can find the updated file on my Google Drive.

And we will copy-paste the whole column to the Server's cmd tool.  We are getting the feedback that the users are created



We can confirm by checking the newly created users on the OU. 






No comments:

Post a Comment

Cisco Call Manager - Create Unattended File

CUC and CUCM installation wizard has a lot of steps that require user's input. Luckily we can specify an unattende...