I'm trying to get a list of users that are members of an Active Directory group that are not disabled. The best I've been able to find so far is:
dsquery group -name "Group name" | dsget group -members -expand | dsget user -samid -disabled -c | findstr /c:" no "
...admitting that the the final 'findstr' is a total hack (and it unfortunately also strips the column headings.)
I have been able to find the following dsquery command that gives a list of all non-disabled users:
dsquery * -filter "(&(sAMAccountType=805306368)(!(userAccountControl:1.2.840.113556.1.4.803:=2)))" -limit 0 | dsget user -samid -c
...but adding a memberOf
parameter only works for groups the users are immediately members of; it doesn't recurse like dsget group
's -expand
does.
So is there a way to combine these, or get dsquery to recurse, or have I gone as far as I can without using PowerShell? (Which I can't because its tools depend on Active Directory Web Services which isn't present on Samba-based domain controllers as of Samba 4.9.5 at least.)