Freigeben über


How to query on a specific attribute (like EmployeeID) and then set other attributes from an answer file

Ldifde and Csvde are great for finding an obect by it's DN, and then adding/modifying/removing attributes on said object. But, what if you want to do the same task, except using a different attribute to find the object in question? By using ADModify and the cmd line tool included with ADModify (admodcmd.exe) we can do just this.

 

In this example, we will:

 

- Perform an LDP query for an attribute (in this case, employeeID)

- The specific value we query for employeeID is taken from the first value on each line inside an answer/input/csv file, which is prepopulated with attributes.

- Once the object with the correct employeeID attribute is found, we then set the respective x other attributes for that object

- The for loop then continues, processing each line of the csv file until all entries are processed

The command is a for loop which calls admodcmd. In this example, we are querying on Employee ID, and then setting 3 other attributes: Company, Department, and Title:

For /f “eol=; tokens=1,2,3,4 delims=, “ %%i in (input.txt) do admodcmd –dn dc=yourdomain,dc=com –p 1000 –s –server <dcname> -f (employeeID=%%i ) –custom company %%j –custom department %%k –custom title %%l

We’re basically telling the for loop to read 4 variables/tokens out of the input.txt file (filename can be anything), and then it passes these 4 values as %%i, %%j, %%k, and %%l - %%i will be the employeeID attribute, which we tell admodcmd to do an LDAP search for. We may need to search the entire domain for the user with said employeeID, but if you know that the target users are all in a specific OU, change the DN you search for the sake of efficiency.

 

Once admodcmd finds the user with that employeeID, it sets company, department, and title using the –custom switches. Then, it goes to the next line in input.txt and starts again for the next employeeID/object.

In this example the formatting inside the input file was:

123456789,Microsoft,ProductSupport,TechLead

987654321,Microsoft,ProductSupport,SupportEngineer

You may need to change the eol or delims section of the for command if your formatting is different inside your input/answer file. The example file represents what a normal csv file would look like.

 

NOTES:

======

 

Download ADModify from:

 

https://www.gotdotnet.com/workspaces/workspace.aspx?id=f5cbbfa9-e46b-4a7a-8ed8-3e44523f32ed

Download link is that the bottom right of the page, under the "Releases" section.