I have managed to get most of what I need done. I can search computers on my domain and then add the names of the computer and properties to a tree view.
I have it so it looks like this
Computers
---ICT01
------Service pack 3
------Last Logged on
------etc etc
---ICT02
Where can I get a list of all the properties I can get data from in regards to a domain computer.
I can pull the results when I know the name of the item but how can I just use no filters and then populate a listbox or treeview with every one so I can look at them?
Thanks for your time
G
I have it so it looks like this
Computers
---ICT01
------Service pack 3
------Last Logged on
------etc etc
---ICT02
Where can I get a list of all the properties I can get data from in regards to a domain computer.
I can pull the results when I know the name of the item but how can I just use no filters and then populate a listbox or treeview with every one so I can look at them?
Thanks for your time
G
VB.NET:
Imports System.DirectoryServices
Public Class Form1
Dim dirEntry As DirectoryEntry
Dim results As System.DirectoryServices.SearchResultCollection
Dim nodecount As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TreeView1.Nodes.Add(New TreeNode("Computers"))
Dim nodecount = 0
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Using searcher As New System.DirectoryServices.DirectorySearcher
Dim sf As String
Dim mydom As String
mydom = TextBox2.Text
sf = TextBox1.Text
searcher.SearchRoot = New System.DirectoryServices.DirectoryEntry("LDAP://DC=" + mydom + ",DC=stname,DC=org,DC=uk")
searcher.Filter = sf '(&(objectCategory=computer) (name=I*))
'searcher.PropertyNamesOnly = true
searcher.PropertiesToLoad.Add("name")
searcher.PropertiesToLoad.Add("operatingSystemServicePack")
'searcher.PropertiesToLoad.Add("")
searcher.Sort = New System.DirectoryServices.SortOption("name", System.DirectoryServices.SortDirection.Ascending)
searcher.SearchScope = DirectoryServices.SearchScope.Subtree
searcher.SizeLimit = 0
searcher.PageSize = 250
results = searcher.FindAll
If results IsNot Nothing Then
For Each result As System.DirectoryServices.SearchResult In results
'get the actual directory
Dim dir As System.DirectoryServices.DirectoryEntry = result.GetDirectoryEntry
'within the organizational unit there are child entries
For Each childDirectory As System.DirectoryServices.DirectoryEntry In dir.Children
Next
TreeView1.Nodes(0).Nodes.Add(New TreeNode(dir.Properties.Item("name").Value))
TreeView1.Nodes(0).Nodes(nodecount).Nodes.Add(New TreeNode(dir.Properties.Item("operatingSystemServicePack").Value))
nodecount = nodecount + 1
Next
End If
End Using
End Sub
End Class
Last edited: