Query Active Directory to get Description of Server or Computer

Hello Experts

I am trying to query active directory by Computer/Server Name using vb.net to get description. Anyone have any idea how to do this? I'm thinking I need to query LDAP.

Found this not sure were to start the Server name it needs to query is in a label named server.txt. Just need to pull back description to populate decription.text

Dim RootDSE As New DirectoryServices.DirectoryEntry("LDAP://RootDSE")
Dim DomainDN As String = RootDSE.Properties("DefaultNamingContext").Value
Dim ADEntry As System.DirectoryServices.DirectoryEntry = New
System.DirectoryServices.DirectoryEntry("LDAP://" & DomainDN)
Dim ADSearcher As System.DirectoryServices.DirectorySearcher = New
System.DirectoryServices.DirectorySearcher(ADEntry )
ADSearcher.Filter = ("(objectClass=computer)")
Dim SearchEntry As System.DirectoryServices.SearchResult
For Each SearchEntry In ADSearcher.FindAll()

Console.WriteLine(":Processing:" &
Mid(SearchEntry.GetDirectoryEntry().Name.ToString( ), 4))

Catch ex As Exception
Console.WriteLine("Trying to Connect to: " & _
SearchEntry.GetDirectoryEntry().Name.ToString() & vbCrLf &
End Try


End Try
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


Please find the Ldap Query which will find the Computer and server with Description


Please update if you require more info
marcuschangDeveloperAuthor Commented:
Where would I plug in the Computer Name I am trying to get description for?
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

marcuschangDeveloperAuthor Commented:
       Dim adrootEntry As New DirectoryEntry("flsxxxx", "xxxx", "xxxx")
        Dim adEntry As New System.DirectoryServices.DirectoryEntry("LDAP://DC=cxxx,DC=cxxxxx,DC=com")
        Dim adSearcher As New System.DirectoryServices.DirectorySearcher(adEntry)
        Dim adSearcherResult As System.DirectoryServices.SearchResult
        Dim adResultEntry As System.DirectoryServices.DirectoryEntry

        adSearcher.Filter = "(&(objectClass=computer) (cn=" & xxxxxxxText & "))"


            adSearcherResult = adSearcher.FindOne

            adResultEntry = adSearcherResult.GetDirectoryEntry()

            Server_InfoTextBox.Text = Server_InfoTextBox.Text & " " & getProperty(adResultEntry, "Description", "")

        Catch e As Exception
            MsgBox("Problem finding the description of this server in Active Directory" & e.ToString)
            ' GetComputerOS = "Not Found"
        End Try

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
marcuschangDeveloperAuthor Commented:
This last one did the trick
marcuschangDeveloperAuthor Commented:
Pieced It together
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.