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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In this article, we will see the basic design consideration while designing a Multi-tenant web application in a simple manner. Though, many frameworks are available in the market to develop a multi - tenant application, but do they provide data, cod…
In this article, I am going to show you how to simulate a multi-site Lab environment on a single Hyper-V host. I use this method successfully in my own lab to simulate three fully routed global AD Sites on a Windows 10 Hyper-V host.
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 Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

911 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

19 Experts available now in Live!

Get 1:1 Help Now