Solved

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

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to resolve user quota error? 13 71
extend monitor issues 6 29
is a 3rd party application able to write events to the security log? 4 24
Reinstall Windows 10 3 17
Our Group Policy work started with Small Business Server in 2000. Microsoft gave us an excellent OU and GPO model in subsequent SBS editions that utilized WMI filters, OU linking, and VBS scripts. These are some of experiences plus our spending a lo…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

803 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