List of computers in Active Directory that are online

ぃ、小莉子 提交于 2019-12-04 16:58:00

I know it's a bit old, but for others...this snippet will return a 760 computer names from a domain using AD within 2-3 seconds....a significant improvement....enjoy!

    Friend Shared Function DomainComputers() As Generic.List(Of String)

    ' Add a Reference to System.DirectoryServices

    Dim Result As New Generic.List(Of String)

    Dim ComputerName As String = Nothing
    Dim SRC As SearchResultCollection = Nothing
    Dim Searcher As DirectorySearcher = Nothing

    Try

        Searcher = New DirectorySearcher("(objectCategory=computer)", {"Name"})

        Searcher.Sort = New SortOption("Name", SortDirection.Ascending)
        Searcher.Tombstone = False

        SRC = Searcher.FindAll

        For Each Item As SearchResult In SRC
            ComputerName = Item.Properties("Name")(0)
            Result.Add(ComputerName)
        Next

    Catch ex As Exception

    End Try

    Return Result

End Function

I would look at Linq To Active Directory found on CodePlex

You'd also have to define "my network". Your subnet? Your Organizational Unit? Your domain? Your forest?

Also consider where your LDAP server is that you are querying. Is it close or is it on the other end of a remote link?

Also what do you consider "online"? Do you expect to be able to ping it? Do you expect to be able to connect to it and perform an operation?

There are many things to consider here. Also if you have other infrastructure components such as an SCCM / SMS server they can often be queried much faster since all of the discovery data has flowed up into the data warehouse.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!