Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Can DSQUERY commands be piped together?

eg to return a list of users in each of the groups found within the 'Builtin' container?

dsquery groups "cn=Builtin,dc=domain,dc=company" | dsquery groups "cn=%builtingroups%cn=Builtin,dc=domain,dc=company" -members >>usergroups.txt

Where %builtingroups% is the result of the first query (ie a list of groups)


share|improve this question
I think this question is similar but doesn't return the result i'm looking for (ie a user list within every group contained per container) –  HaydnWVN Jan 9 '12 at 12:44

1 Answer 1

up vote 2 down vote accepted
for /f "usebackq delims=" %a in (`dsquery group "cn=Builtin,dc=domain,dc=company"`) do echo ===%a members: >> members.txt && dsget group %a -members >> members.txt
share|improve this answer
thanks, i'll try it later! Care to explain what each part does? I can partly figure it out myself... :) –  HaydnWVN Jan 10 '12 at 13:10
Well, it gets list of groups with "dsquery group", then it goes through that list and for each line calls dsget to pick members. "echo ... &&" is just to make output more readable so you can omit that. Type "for /?" for usebackq and delims explanation. It will be more clear when you look at it running. –  dusan.bajic Jan 10 '12 at 13:27
Excellent, thanks! :) –  HaydnWVN Jan 10 '12 at 13:40
dsquery failed:A referral was returned from the server. Any ideas to troubleshoot? –  HaydnWVN Jan 11 '12 at 19:44
try dsquery alone: dsquery group "cn=Builtin,dc=domain,dc=company", it is usually a typing error –  dusan.bajic Jan 12 '12 at 13:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.