DARkTYranno Digital Hobbies

Different hobby Projects I have/had, together on 1 site!
HomeHome  FAQFAQ  SearchSearch  MemberlistMemberlist  UsergroupsUsergroups  RegisterRegister  Log inLog in  

Share | 

 VbScript - Add Users to Active Directory Server Automatically!

Go down 

Aantal berichten : 23
Registratiedatum : 2013-12-23
Leeftijd : 26

PostSubject: VbScript - Add Users to Active Directory Server Automatically!   Mon 03 Mar 2014, 8:40 am

Automatically Add Users from Excel File to Active Directory Script

Created using Visual Basic Script Language (NotePad)

At school I was in a group of Server Managers. They asked me once to add all the students from different groups to our Active Directory Server.
It would take quite a long time to set all the First/Last names, passwords and some options per person, with the chance of typing mistakes.
We also had no backup, meaning that whenever the power went down or system crashed, we could start over adding everyone again...
So I took my time to find a way to automatically add all those people, as we had an excel file with all students in it to check if they were present!
Using VBScript I found a way to directly add the people to Active Directory and loop it, depending on the group they were in (Excel Sheet number).
In the following movie I show a demonstration of what you would normally have to do and what my script does.
I don't show the code as it's over 1300 lines of code, but you can download my project code using the link in movie description on youtube, to test it yourself.

As you can see, I start with a demonstration of doing manual tasks to add people and fill in the details we need.
When using direct scripting, I can make this process very fast, accurate and easy.
The part of code to fill in all these details on background:

' --- _Add_the_values_to_the_created_UserObject_ ---
Set objUser = objContainer.Create("User", "cn=" & TName)
objUser.sAMAccountName = Nr(1)
objUser.givenName = FName(0)
objUser.displayName = TName
objUser.userPrincipalName = Nr(1)
objUser.sn = LName

' --- _Add_a_predefined_password_to_the_User_Account_ ---
   strPWD = "Roc2012"
  objUser.userAccountControl = 512
  objUser.pwdLastSet = 0
  objUser.SetPassword strPWD

The variables like TName etc are made up earlier in the script when searching for a specific field in Excel.
Now we use those values for the options of the User we create.

The script I made makes many textfiles to check what is in Active Directory, what in Excel,
differences (what exists only on left/right side), so which users need to be added/removed from Active Directory.

As I was a beginner, this code isn't perfect for many programmers. But for me it worked and that's all that matters.
It took me about 3 weeks (not 24/7!) to create this script in a Virtual Machine with Windows Server 2008 R2 environment.
Back to top Go down
View user profile http://darktyranno.myrealboard.com
VbScript - Add Users to Active Directory Server Automatically!
Back to top 
Page 1 of 1
 Similar topics
» So I got off my lazy ass and have my Minecraft server up again.
» RSS-feed Directory of best Free Marketing Tips
» Which of your plecos are most likely to be active in the daytime?
» RSS-feed Directory of best Free Marketing Tips
» Tournament at Active Game Collections, 3 Nov (Sat)

Permissions in this forum:You cannot reply to topics in this forum
DARkTYranno Digital Hobbies :: Hobbies :: Programming-
Jump to: