Solved

How do I get all usernames and names of users in group name HspGroupName

Posted on 2015-02-11
2
77 Views
Last Modified: 2015-02-17
running this query only gets me 1 name in the table 2.txt and 1.txt table has about 20 usrs -- how could I have it include all names in 1.txt

Unless there's another way, I need to know all the user names and full names in a specific groupname...


cls
@echo off
echo Processing DSQUERY to obtain MEMBER names....
dsquery group DC=hospitals,DC=local -name HspGroupName %1 | dsget group -members > c:\temp

\1.txt
echo DSQUERY MEMBERS -- DONE!
echo Processing DSQUERY to obtain account names....
for /F "tokens=*" %%A in (c:\temp\1.txt) do dsquery * %%A -attr sAMAccountName name > c:\temp\2.txt

Open in new window

0
Comment
Question by:epicazo
2 Comments
 
LVL 83

Accepted Solution

by:
oBdA earned 500 total points
ID: 40605040
That's because the redirected output of the "for /f" loop always overwrites 2.txt, so the last entry wins.
Either delete 2.txt before the loop starts and use >>C:\temp\2.txt, or put round brackets around the whole loop command, before the redirection:
cls
@echo off
echo Processing DSQUERY to obtain MEMBER names....
dsquery group DC=hospitals,DC=local -name HspGroupName %1 | dsget group -members > c:\temp

\1.txt
echo DSQUERY MEMBERS -- DONE!
echo Processing DSQUERY to obtain account names....
(for /F "tokens=*" %%A in (c:\temp\1.txt) do dsquery * %%A -attr sAMAccountName name) > c:\temp\2.txt

Open in new window

0
 

Author Closing Comment

by:epicazo
ID: 40614766
sry for delay.  thanks
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
This is an article about Leadership and accepting and adapting to new challenges. It focuses mostly on upgrading to Windows 10.
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

746 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

13 Experts available now in Live!

Get 1:1 Help Now