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
969 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
[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
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

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Active Directory security has been a hot topic of late, and for good reason. With 90% of the world’s organization using this system to manage access to all parts of their IT infrastructure, knowing how to protect against threats and keep vulnerabil…
Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
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 configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

726 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