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.
Creating a user account in Active Directory
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.
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.
Re: Creating a user account in Active Directory
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
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
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.
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.