Solved

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

Posted on 2015-02-11
2
85 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
[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 Comments
 
LVL 84

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
This article summaries thoughts and ideas from two years of sustained use. It provides good reasoning to make the jump to Windows 10.
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

730 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