Imports System.DirectoryServices
Imports ActiveDs
Module Module1
Sub Main()
' connect to my Active Directory
Dim root As New DirectoryEntry("LDAP://MyDomainControllerServer/dc=digeratisoftware,dc=local")
Try
' create a new user object whose RDN is John Brennan
Dim user As DirectoryEntry = root.Children.Add("CN=John Brennan", "user")
' set properties on the user
user.Properties("givenName").Value = "John"
user.Properties("sn").Value = "Brennan"
user.Properties("mail").Value = "john@somemailaddress.com"
user.Properties("description").Value = "new test user"
user.Properties("sAMAccountName").Value = "John.Brennan"
' userPrincipalName. This property is domain specific
user.Properties("description").Value = "John.Brennan@digeratsoftware.local"
' enable the user account and set their password to never expire
user.Properties("userAccountControl").Value = ADS_USER_FLAG.ADS_UF_NORMAL_ACCOUNT Or ADS_USER_FLAG.ADS_UF_PASSWD_NOTREQD Or ADS_USER_FLAG.ADS_UF_DONT_EXPIRE_PASSWD
' commit the object from memory to the directory store
user.CommitChanges()
' next set the user's password
user.Invoke("SetPassword", New Object() {"mypassword"})
Catch ex As Exception
Throw
End Try
End Sub
End Module
|