Creating a user account in Active Directory

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
bareedaa
Posts: 5
Joined: Mon May 20, 2013 12:55 pm

Creating a user account in Active Directory

Post by bareedaa » Thu May 30, 2013 12:33 pm

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.

User avatar
bareedaa
Posts: 5
Joined: Mon May 20, 2013 12:55 pm

Re: Creating a user account in Active Directory

Post by bareedaa » Thu May 30, 2013 2:14 pm

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

User avatar
jvierra
Posts: 13479
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Creating a user account in Active Directory

Post by jvierra » Thu May 30, 2013 3:14 pm

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.

Locked