Solved

Find employeeID and emploeeNumber from AD using VB.NET

Posted on 2010-09-20
2
1,428 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 500 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

690 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