Chris Jones
asked on
connect to AD in vb.net and update AD
Hello,
i have a project that i am having a hard time with i need to be able to read any ad user from our server and update there records as well as add them and remove them from groups.
i have a project that i am having a hard time with i need to be able to read any ad user from our server and update there records as well as add them and remove them from groups.
ASKER
i get a few errorsd in my function that i got from the first post
''' <summary>
''' Method that updates user's properties
''' </summary>
''' <param name="userLogin">Login of the user to update</param>
''' <param name="userDepartment">New department of the specified user</param>
''' <param name="userTitle">New title of the specified user</param>
''' <param name="userPhoneExt">New phone extension of the specified user</param>
Public Sub UpdateUserADAccount(ByVal userLogin As String, ByVal userDepartment As String, ByVal userTitle As String, ByVal userPhoneExt As String)
Dim dirEntry As DirectoryEntry = GetDirectoryEntry()
Dim dirSearcher As DirectorySearcher = New DirectorySearcher(dirEntry )
' 1. Search the Active Directory for the speied user
dirSearcher.Filter = "(&(objectCategory=Person) (objectCla ss=user) (SAMAccountName=" & userLogin & "))"
dirSearcher.SearchScope = SearchScope.Subtree
Dim searchResults As SearchResult = dirSearcher.FindOne()
If Not searchResults Is Nothing Then
Dim dirEntryResults As New DirectoryEntry(results.Pat h)
'The properties listed here may be different then the
'properties in your Active Directory so they may need to be
'changed according to your network
' 2. Set the new property values for the specified user
SetProperty(dirEntryResult s, "department", userDepartment)
SetProperty(dirEntryResult s, "title", userTitle)
SetProperty(dirEntryResult s, "phone", userPhoneExt)
' 3. Commit the changes
dirEntryResults.CommitChan ges()
' 4. Close & Cleanup
dirEntryResults.Close()
End If
' 4a. Close & Cleanup
dirEntry.Close()
End Sub
ERRORS
Error 4 'results' is not declared. It may be inaccessible due to its protection level. C:\Code\PartalGroups\Parta lGroups\LD AP.vb 120 55 PartalGroups
Error 5 'SetProperty' is not declared. It may be inaccessible due to its protection level. C:\Code\PartalGroups\Parta lGroups\LD AP.vb 125 13 PartalGroups
Error 6 'SetProperty' is not declared. It may be inaccessible due to its protection level. C:\Code\PartalGroups\Parta lGroups\LD AP.vb 126 13 PartalGroups
Error 7 'SetProperty' is not declared. It may be inaccessible due to its protection level. C:\Code\PartalGroups\Parta lGroups\LD AP.vb 127 13 PartalGroups
''' <summary>
''' Method that updates user's properties
''' </summary>
''' <param name="userLogin">Login of the user to update</param>
''' <param name="userDepartment">New department of the specified user</param>
''' <param name="userTitle">New title of the specified user</param>
''' <param name="userPhoneExt">New phone extension of the specified user</param>
Public Sub UpdateUserADAccount(ByVal userLogin As String, ByVal userDepartment As String, ByVal userTitle As String, ByVal userPhoneExt As String)
Dim dirEntry As DirectoryEntry = GetDirectoryEntry()
Dim dirSearcher As DirectorySearcher = New DirectorySearcher(dirEntry
' 1. Search the Active Directory for the speied user
dirSearcher.Filter = "(&(objectCategory=Person)
dirSearcher.SearchScope = SearchScope.Subtree
Dim searchResults As SearchResult = dirSearcher.FindOne()
If Not searchResults Is Nothing Then
Dim dirEntryResults As New DirectoryEntry(results.Pat
'The properties listed here may be different then the
'properties in your Active Directory so they may need to be
'changed according to your network
' 2. Set the new property values for the specified user
SetProperty(dirEntryResult
SetProperty(dirEntryResult
SetProperty(dirEntryResult
' 3. Commit the changes
dirEntryResults.CommitChan
' 4. Close & Cleanup
dirEntryResults.Close()
End If
' 4a. Close & Cleanup
dirEntry.Close()
End Sub
ERRORS
Error 4 'results' is not declared. It may be inaccessible due to its protection level. C:\Code\PartalGroups\Parta
Error 5 'SetProperty' is not declared. It may be inaccessible due to its protection level. C:\Code\PartalGroups\Parta
Error 6 'SetProperty' is not declared. It may be inaccessible due to its protection level. C:\Code\PartalGroups\Parta
Error 7 'SetProperty' is not declared. It may be inaccessible due to its protection level. C:\Code\PartalGroups\Parta
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks that works
ASKER
i have been trying to display all of my groups is there soem code that can help me use these provided functions.
ASKER
any ideals
try. :
Public Function GetAllADGroups() As List(Of String)
Try
Dim myDirectory As DirectoryEntry = GetDirectoryEntry()
Dim mySearcher As New DirectorySearcher(myDirectory)
Dim mySearchResultColl As SearchResultCollection
Dim mySearchResult As SearchResult
Dim result As New List(Of String)
Dim objGroupEntry As DirectoryEntry
' Build LDAP query
mySearcher.Filter = "(&(objectClass=group))"
mySearchResultColl = mySearcher.FindAll()
' enumerate
If (mySearchResultColl.Count <> 0) Then
For Each mySearchResult In mySearchResultColl
objGroupEntry = mySearchResult.GetDirectoryEntry()
result.Add(objGroupEntry.Name)
Next
End If
' return value
Return result
Catch ex As System.Exception
Return Nothing
End Try
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
i get this eror when i run the above function
Exception has been thrown by the target of an invocation.
Exception has been thrown by the target of an invocation.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
i was removed from this project by my job thanks for helping everyone
ASKER
I've requested that this question be deleted for the following reason:
no longer need help
no longer need help
The question has been answered and further help given points should be awarded
3) Accept one or more Expert posts as the answer
100 points : http:#37812604
300 points : http:#37823187
100 points : http:#37825807
The reason I have assigned points this way is these expert responses are the only ones that attempted to help the user, and posting links without following up should be discouraged.
100 points : http:#37812604
300 points : http:#37823187
100 points : http:#37825807
The reason I have assigned points this way is these expert responses are the only ones that attempted to help the user, and posting links without following up should be discouraged.
Suspend a user's account
Enable a user's account
Reset a user's password
Update a user account
Add a user to a specific group
Remove a user from a group
Retrieve the list of all groups a user is a member of
Retrieve all computers connected to the network
Determine if a user's account is disabled
Check if a user account is active (perform a basic login)
Please refer to http://www.codeproject.com/Articles/19689/Working-with-Active-Directory-in-VB-NET. Hopefully this will be helpful.
Good Luck!