Page 1 of 1

Creating a user account in Active Directory

Posted: Thu May 30, 2013 12:33 pm
by bareedaa
I am new to VB:
I would like to have a script that creates a new user name(user account) in active directory with first initial and last name. If the same name already exists add a middle initial. If still exists add a numerical value to the new username.

Re: Creating a user account in Active Directory

Posted: Thu May 30, 2013 2:14 pm
by bareedaa
I have the following script. Please help:


Public Sub CreateAdAccount(ByVal sUserName As String, _
ByVal sPassword As String, _
ByVal sFirstName As String, ByVal sLastName As String, _
ByVal sGroupName As String)
Dim catalog As Catalog = New Catalog()
Dim dirEntry As New DirectoryEntry()

Dim adUsers As DirectoryEntries = dirEntry.Children
Dim newUser As DirectoryEntry = adUsers.Add("CN=" & sUserName, "user")

SetProperty(newUser, "givenname", sFirstName)
SetProperty(newUser, "sn", sLastName)
SetProperty(newUser, "SAMAccountName", sUserName)
SetProperty(newUser, "userPrincipalName", sUserName)
newUser.CommitChanges()

SetPassword(newUser, sPassword)

EnableAccount(newUser)

newUser.Close()
dirEntry.Close()
End Sub

Re: Creating a user account in Active Directory

Posted: Thu May 30, 2013 3:14 pm
by jvierra
Sorry but that is not a script.


Try searching for VBScript. You have posted a VB.Net program function.

You might also start by downloading some of the evaluation tools on this site to help you learn something about writing scripts.
See the links on the top of this page.