Solved

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

Posted on 2015-02-11
2
80 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

Don't lose your head updating email signatures!

Do your end users still have the wrong email signature? Do email signature updates bore you or fill you with a sense of dread? You can make this a whole lot easier on yourself by trusting an Exclaimer email signature management solution. Over 50 million users do...so should you!

Question has a verified solution.

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

This is an article about Leadership and accepting and adapting to new challenges. It focuses mostly on upgrading to Windows 10.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …

896 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

20 Experts available now in Live!

Get 1:1 Help Now