1

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)

Thanks!

HaydnWVN
  • 415
  • 2
  • 8
  • 27
  • I think [this question](http://serverfault.com/questions/212477/dsquery-nested-groups) is similar but doesn't return the result i'm looking for (ie a user list within every group contained per container) – HaydnWVN Jan 09 '12 at 12:44

2 Answers2

2
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
Dusan Bajic
  • 2,056
  • 1
  • 18
  • 21
  • 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
  • `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
  • You did change dc=domain,dc=company with your domain data :) ? – Dusan Bajic Jan 12 '12 at 13:26
  • Errrr, i'll check! Might be my error, sorry :) – HaydnWVN Jan 12 '12 at 17:07
1

In my case, the referral was for a query for a user in a Trusting Domain from a Workstation in the Trusted domain. (One way trust Trusting->Trusted)

From WKS.TRUSTED.DOM

dsquery user "DC=TRUSTING,DC=DOM" -samid <account in Trusting.dom>
dsquery failed:A referral was returned from the server.

Why? Because the Domain Controllers for Trusting.com are all behind a firewall and unreachable.

Additional diagnostic:

dsquery user "DC=TRUSTING,DC=DOM" -samid <account in Trusting.dom> -s DC1.Trusted.dom
dsquery failed:The server is not operational.

When a VPN from the network for WKS.Trusted.DOM is established to the network for Trusting.DOM is established, the query succeeds just fine.

Stefan Lasiewski
  • 23,667
  • 41
  • 132
  • 186
  • 1
    You've posted this as an answer to the original question. Perhaps it is more suited as a comment. – jscott Oct 13 '15 at 19:00