G
Guest
I am using DirectoryServices to get all groups and all users from active
directory. Now I want to use the filter to limit the groups and users. I
would like to remove the builtin groups. I use the code below but the built
in groups are still there. The main question is how do I construct the filter
strings. The code gives me the properties and their values. Do I use these
properties and values in the filter or is there other information I am
missing.
Code:
Dim strDomPath As String =
"LDAP://cd2k3domtest/DC=CDTESTDOM,DC=adwaresystems,DC=com"
Dim dirEnt As New DirectoryEntry(strDomPath)
Dim dsgroups As New DirectorySearcher(dirEnt)
dsgroups.SearchScope = SearchScope.Subtree
dsgroups.Filter =
"(&(objectCategory=group)(!distinguishedname=Builtin))"
Dim srGroupsCol As SearchResultCollection
Try
srGroupsCol = dsGroups.FindAll()
Catch domE As Exception
Dim str As String
str = domE.Message
End Try
Dim objarray() As String
ReDim objarray(35)
Dim arrGroup As New ArrayList
Dim srGroups As SearchResult
For Each srGroups In srGroupsCol
'will get all property names that are available
srGroups.Properties.PropertyNames.CopyTo(objarray, 0)
Dim i As Integer
For i = 0 To objarray.Length - 1
Try
Dim strPro As String = CType(objarray(i).ToString, String)
Response.Write(strPro & " " &
srGroups.Properties(strPro).Item(0).ToString & "<br />")
Catch
End Try
Next
Response.Write("*************************************************************<br />")
Next
directory. Now I want to use the filter to limit the groups and users. I
would like to remove the builtin groups. I use the code below but the built
in groups are still there. The main question is how do I construct the filter
strings. The code gives me the properties and their values. Do I use these
properties and values in the filter or is there other information I am
missing.
Code:
Dim strDomPath As String =
"LDAP://cd2k3domtest/DC=CDTESTDOM,DC=adwaresystems,DC=com"
Dim dirEnt As New DirectoryEntry(strDomPath)
Dim dsgroups As New DirectorySearcher(dirEnt)
dsgroups.SearchScope = SearchScope.Subtree
dsgroups.Filter =
"(&(objectCategory=group)(!distinguishedname=Builtin))"
Dim srGroupsCol As SearchResultCollection
Try
srGroupsCol = dsGroups.FindAll()
Catch domE As Exception
Dim str As String
str = domE.Message
End Try
Dim objarray() As String
ReDim objarray(35)
Dim arrGroup As New ArrayList
Dim srGroups As SearchResult
For Each srGroups In srGroupsCol
'will get all property names that are available
srGroups.Properties.PropertyNames.CopyTo(objarray, 0)
Dim i As Integer
For i = 0 To objarray.Length - 1
Try
Dim strPro As String = CType(objarray(i).ToString, String)
Response.Write(strPro & " " &
srGroups.Properties(strPro).Item(0).ToString & "<br />")
Catch
End Try
Next
Response.Write("*************************************************************<br />")
Next