Solved

How do I search a text file with employee numbers and do a 'For' 'Do' loop using dsquery to search AD using the contents of the text file.

Posted on 2008-10-17
5
961 Views
Last Modified: 2012-06-27
Hello,

How do I search a text file with employee numbers and do a 'For' 'Do' loop using dsquery to search AD using the contents of the text file.

Example
Myfile.txt will contain several hundred employee ids.
Use DSQUERY to look up AD and return certain attributes depending what is being asked. Trying to use the 'For' 'Do' lookup as in the following command.

for /f %%a in (myfile.txt) do dsquery * -filter "((&(objectCategory=Person)(objectClass=User)(employeeid goes here)))" -attr cn mail homemdb proxyaddresses -L

Obviously this does not work as it cannot search myfile.txt and replace (employeeid goes here) with the recently searched value.

This is how the command would look if I searched for an individual employee id.

dsquery * -filter "((&(objectCategory=Person)(objectClass=User)(employeeID=00091194)))" -attr cn mail homemdb proxyaddresses -L

Not looking for any VB script, just dsquery and the loop statement.

Thanks
0
Comment
Question by:Neiphin
  • 2
  • 2
5 Comments
 
LVL 18

Expert Comment

by:exx1976
ID: 22742164
VBscript would be way easier...  Expand your mind.  :-)
0
 
LVL 6

Author Comment

by:Neiphin
ID: 22742216
perhaps, but my knowledge of VB is less than my knowledge of DOS.... :-)))
0
 
LVL 18

Expert Comment

by:exx1976
ID: 22742340
Understood, but we all need to start somewhere.  If I'm looking at that correctly, you will provide a text file of employeeID's, one per line, and you want a corresponding text file to contain the email addresses that correspond to that employeeID?  Anything else?
0
 
LVL 21

Accepted Solution

by:
AmazingTech earned 125 total points
ID: 22742474
You mean this?
for /f %%a in (myfile.txt) do dsquery * -filter "((&(objectCategory=Person)(objectClass=User)(employeeid=%%a)))" -attr cn mail homemdb proxyaddresses -L

Open in new window

0
 
LVL 6

Author Comment

by:Neiphin
ID: 22742732
Way to go AmazingTech. Works like a dream and so simple.

Many thanks

Thanks also to exx1976 for the encouragement to go towards VB.... :-)

Regards
0

Join & Write a Comment

Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Disabling the Directory Sync Service Account in Office 365 will stop directory synchronization from working.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now