nightshadz
asked on
Visual Basic .NET & Active Directory filter/search
Below is an AD Schema I have set up in a test environment. My requirement is to loop through all of the members in the "RSA Users" and set a complex password.
I have most of the code set up already but I'm not sure how to access the "RSA Users" group, loop through all the members in there, and set their password.
I have most of the code set up already but I'm not sure how to access the "RSA Users" group, loop through all the members in there, and set their password.
Imports System
Imports System.DirectoryServices
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dirEntry As DirectoryEntry = GetDirectoryEntry()
Dim dirSearcher As DirectorySearcher = New DirectorySearcher(dirEntry)
dirSearcher.Filter = ""
dirSearcher.SearchScope = SearchScope.Subtree
Dim searchResults As SearchResult = dirSearcher.FindOne()
If Not searchResults Is Nothing Then
Dim dirEntryResults As New DirectoryEntry(searchResults.Path)
'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(dirEntryResults, "lwsimsid", "1156")
' 3. Commit the changes
dirEntryResults.CommitChanges()
' 4. Close & Cleanup
dirEntryResults.Close()
End If
' 4a. Close & Cleanup
dirEntry.Close()
End Sub
Public Shared Function GetDirectoryEntry() As DirectoryEntry
Dim dirEntry As DirectoryEntry = New DirectoryEntry()
dirEntry.Path = "LDAP://OU=APPLICATION GROUPS,DC=Test,DC=local"
Return dirEntry
End Function
Public Shared Sub SetProperty(ByVal de As DirectoryEntry, ByVal PropertyName As String, ByVal PropertyValue As String)
If Not PropertyValue Is Nothing Then
If de.Properties.Contains(PropertyName) Then
de.Properties(PropertyName)(0) = PropertyValue
Else
de.Properties(PropertyName).Add(PropertyValue)
End If
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim i As Integer
For i = 1 To 20
Debug.Print(RandomPassword.Generate(10))
Next
End Sub
End Class
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Open in new window