Avatar of Simon336697
Simon336697
Flag for Australia asked on

Looping through a text file that contains a list of groups

Hi everyone hope you are all well.

Guys I have the following command that does what Id like but it only does it on ONE group specified, as the following shows:

dsquery group -name "AU-SG GROUPX" | dsget group -members | dsget user -samid

Output of the above command gives a list of users for the group AU-SG GROUPX, as the following shows:

samid
msimons
ajones
 tsmith


What id like to do is the following:

Instead of having to input the group name after the -name switch, as follows:
dsquery group -name "AU-SG GROUPX" | dsget group -members | dsget user -samid

Id like to be able to point the -name switch to a text file of group names, then loop through each group name in a text file, and output the usernames.

eg.

dsquery group -name c:\groups.txt | dsget group -members | dsget user -samid

Any help on this greatly appreciated.



VB Script

Avatar of undefined
Last Comment
Simon336697

8/22/2022 - Mon
Aard Vark

Try this. You would use %a on the command line and %%a in a batch file.

for /f "usebackq" %%a in (`type c:\groups.txt`) do (dsquery group -name %a | dsget group -members | dsget user -samid)

Open in new window

ASKER CERTIFIED SOLUTION
Aard Vark

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Simon336697

ASKER
Hi Learnctx. Thanks so much for your kind help
Learnctx, can i ask you, what is hte "usebackq" for?
Thanks so much.
Simon336697

ASKER
Thanks Learn i figured it out thanks so much.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck