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
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
968 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

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Resolve DNS query failed errors for Exchange
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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 …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

840 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