Piping DSQUERY commands together

active-directorycommand-line-interfacedsquerywindows-server-2003

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!

Best Answer

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