Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Visual Basic ( VB ) (http://www.go4expert.com/forums/visual-basic/)
-   -   Query Active Directory using Employee ID (http://www.go4expert.com/forums/query-active-directory-using-employee-id-t12353/)

RTorres9 22Jul2008 23:33

Query Active Directory using Employee ID
 
Hello Guy's

I need help on developing a query script to search for specific employee ID. Currently I'm having to disable about 50 user accounts per day and need a script to help me program this. I've developed some code already that read's a value from a file and then it queries AD but is not finding anything when I search for the value of the "Employee ID" value.

When I change to code to query for a specific user's job title it does fine accounts.

Here is the code that I have put together already but it's coming up empty when I look for specific employee id's.
Code:

Dim sCSVFile, objFSO, objTextFile
Dim qQuery, objConnection, objCommand, objRecordSet
Dim objUser

Dim sempid        'usage to capture the user's employee ID
Dim suserid        'usage to capture the user's sAMAccountname
Dim supn        'usage to capture the user's usersprincipalname
Dim suname        'usage to capture the user's full name
Dim susn                'usage to capture the user's surname
Dim sugn        'usage to capture the user's givenname

Const ForReading = 1

sCSVFile = "C:\repository\test\refemployid.csv"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(sCSVFile,ForReading)

Do Until objTextFile.AtEndOfStream
        TxtIn = objTextFile.ReadLine

        qQuery = "<LDAP://dc=yisd,dc=net>;" & _
                "(&(objectCategory=user)(employee ID=TxtIn));" &_
                        "sAMAccountName,adspath;subtree"
       
        Set objConnection = CreateObject("ADODB.Connection")
        Set objCommand = CreateObject("ADODB.Command")
        Set objRecordSet = CreateObject("ADODB.Recordset")

        objConnection.Open "Provider=ADsDSOObject;"
        objCommand.ActiveConnection = objConnection
        objCommand.Properties("page size")= 100
        objCommand.CommandText = qQuery
        Set objRecordSet = objCommand.Execute

        While Not objRecordSet.EOF
        Set objUser = GetObject(objRecordSet("adspath"))
                RDData                                        'Read attributes into variables
                VWData
                'WDData                                        'Write data to file
                objRecordSet.MoveNext
        Wend
                'WScript.Echo objuser.employeeID
                'WScript.Echo objuser.userPrincipalName
                'WScript.Echo objuser.name
                'WScript.Echo objuser.sn

'objcsv.close
objConnection.Close

Loop

        Sub RDData
                sempid = objuser.employeeID
                suserid        = objuser.sAMAccountName
                supn = objuser.userPrincipalName
                suname = objuser.name
                susn = objuser.sn
                sugn = objuser.givenName
        End Sub
       
        Sub VWData
                WScript.Echo sempid
                WScript.Echo sserid
                WScript.Echo supn
                WScript.Echo suname
                WScript.Echo suserid
                WScript.Echo sugn
        End Sub
       
WScript.Echo "Finished - All Done"

Any assistance would be greatly appreciated, Thanks.

RogerAndes 3Oct2008 19:34

Re: Query Active Directory using Employee ID
 
Hey man lose the space between employee and ID in your ldap command. that should get you goin

ssampati 11Nov2008 01:40

Re: Query Active Directory using Employee ID
 
Guys: i need some more help in using this script. What is the format of csv file? can i replace employeeid with employeenumber?

In my org ...we have employeenumber attribute for employee id;s. i have a requirement to read the employee id's from a text/csv file and disable those id's and move them to a new ou called "disabled accts"

Any help greatly appreciated.

-Sreenu


All times are GMT +5.5. The time now is 06:08.