?
Solved

Find employeeID and emploeeNumber from AD using VB.NET

Posted on 2010-09-20
2
Medium Priority
?
1,461 Views
Last Modified: 2012-05-10
Hi,

Is it possible to find out a employeeID and employeeNumber from a specified computer using VB.NET.

I know this is possible using VBS, but I dont know how to convert it. Here is the code for VBS

Thank you
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000
 objCommand.Properties("Searchscope") = strSQL 
    strSearch = LCase(searchbox.value)
    objCommand.CommandText = "SELECT ADsPath FROM 'LDAP://"& FQDN &"' WHERE objectCategory='computer' and employeeNumber='*" & strSearch
    Set objRecordSet = objCommand.Execute

Open in new window

0
Comment
Question by:DanielBlackmore
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 42

Expert Comment

by:sedgwick
ID: 33723085
there's no EmployeeName to computer objects in AD , only employeeID.

to get employeeID of computer object in AD use the following code.
usage:

string id = FindComputerEmployeeID("LDAP://cn=computers,DC=soap,DC=com", "COMP1");

static string FindComputerEmployeeID(string LdapRootPath, String computer)
        {
            try
            {
                DirectorySearcher search = new DirectorySearcher(LdapRootPath);
                search.Filter = "(&(objectCategory=computer)(sAMAccountName=" + computer + "$))";
                search.PropertiesToLoad.Add("employeeID");

                SearchResult result = search.FindOne();

                if (result != null)
                {
                    return result.Properties["employeeID"][0].ToString();
                }
            }
            catch (Exception ex)
            {
                string debug = ex.Message;
            }
            return null;
        }

Open in new window

0
 
LVL 42

Accepted Solution

by:
sedgwick earned 2000 total points
ID: 33723093
here's in vb.net
Private Shared Function FindComputerEmployeeID(computer As [String]) As String
	Try
		Dim search As New DirectorySearcher("LDAP://cn=computers,DC=soap,DC=com")
		search.Filter = "(&(objectCategory=computer)(sAMAccountName=" & Convert.ToString(computer) & "$))"
		search.PropertiesToLoad.Add("employeeID")

		Dim result As SearchResult = search.FindOne()

		If result IsNot Nothing Then
			Return result.Properties("employeeID")(0).ToString()
		End If
	Catch ex As Exception
		Dim debug As String = ex.Message
	End Try
	Return Nothing
End Function

Open in new window

0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month14 days, 12 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question