?
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
Medium Priority
?
974 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 500 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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
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…
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 …
Suggested Courses

777 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