Link to home
Start Free TrialLog in
Avatar of every1isevil2
every1isevil2Flag for United States of America

asked on

Need correct syntax for DSQUERY and DSGET operation.

I need to query a specific group in our AD forest call "Part-time staff" to return the user name(CN) and smtp email addresses of those users to a text file.  I have been experimenting with this and have not been able to get the results I need.
Avatar of Pber
Pber
Flag of Canada image

Try this:
 
dsquery group -name "Part-time staff" | dsget group -members -expand
 
The -expand on the end is optional if you want to show the membership of nested groups
ASKER CERTIFIED SOLUTION
Avatar of Pber
Pber
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can do a:
 dsget user /?
to see what you can extract.  The DN is kind of large.  You can also return samid or display as well:

dsquery group -name "Part-time staff" | dsget group -members | dsget user -samid -email

dsquery group -name "Part-time staff" | dsget group -members | dsget user -display -email
 
To redirect to a text file you just add:
  >yourtextfile.txt
...to the end.
e.g.
dsquery group -name "Part-time staff" | dsget group -members | dsget user -display -email>PartTimeStaff.txt
Avatar of every1isevil2

ASKER

Pber:

Wondeful.  Work sperfectly!  
Just one follow up.  Is there a way to tweak the results to get only the 'CN=First Last' portion?  Right now it gives me:  
CN=First Last,OU=Users,OU=Staff,OU=MCC,DC=staff,DC=morton,DC=edu
Frist.Last@myschool.edu

Which is FINE considering I was not able to get this before.  Thanks again.
This did the trick thanks again!

dsquery group -name "#Part-time faculty" | dsget group -members | dsget user -display -email
glad to help.
I get that command to work on most of my security group except for staff. Maybe because staff have more than 3000 + users. Please advise

dsquery group -name Staff  | dsget group -members | dsget user -email >c:\file.txt  
C:\>dsquery group -name "staff" | dsget group -members | dsget user -display -em
ail >c:\Staff.txt
dsget failed:The parameter is incorrect.
The problem might be you have a nested group or other objects that may not be compliant.  You can add the flag (-c) to continue on errors it should work.

dsquery group -name Staff  | dsget group -members -c | dsget user -emai -c l >c:\file.txt