How can I get Distinguished name for a chosen computer in Active Directory using VB.NET 20017

How can I get Distinguished name for a chosen computer in Active Directory using VB.NET 20017
 Public Sub ADComputers()
        Dim dirEntry As DirectoryEntry = New DirectoryEntry()
                dirEntry.Path = "LDAP://OU=XXX,OU=Computer Accounts,DC=XXX,DC=XXX,DC=XXX,DC=org"

        Dim mySearcher As DirectorySearcher = New DirectorySearcher(dirEntry)
        ' This value can be passed in the constructor if preferred.
        mySearcher.Filter = "(objectClass=Computer)"
        mySearcher.PageSize = 1001

        For Each resEnt As SearchResult In mySearcher.FindOne()
            txtDN.text = (resEnt.Properties("Distinguishedname")(0).ToString())
          End Sub

Open in new window

Tom PowersAsked:
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.

Shaun VermaakTechnical SpecialistCommented:
Change the filter to
mySearcher.Filter = "(&(ObjectCategory=computer)(cn=" + computerName+ "))"; 

Open in new window

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
Tom PowersAuthor Commented:
Shaun Thank You You made my Day.
Shaun VermaakTechnical SpecialistCommented:
Anytime :)
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
Visual Basic.NET

From novice to tech pro — start learning today.