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.
This topic is 10 years and 9 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
bareedaa
Posts: 5
Last visit: Sun Jun 09, 2013 10:24 am

Creating a user account in Active Directory

Post 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.
User avatar
bareedaa
Posts: 5
Last visit: Sun Jun 09, 2013 10:24 am

Re: Creating a user account in Active Directory

Post 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
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Creating a user account in Active Directory

Post 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.
This topic is 10 years and 9 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked