Solved

Need correct syntax for DSQUERY and DSGET operation.

Posted on 2008-10-07
10
1,185 Views
Last Modified: 2013-12-24
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.
0
Comment
Question by:every1isevil2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 2
  • 2
10 Comments
 
LVL 26

Expert Comment

by:Pber
ID: 22662392
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
0
 
LVL 26

Accepted Solution

by:
Pber earned 125 total points
ID: 22662442
woops, you need tne SMTP as well:
dsquery group -name "Part-time staff" | dsget group -members | dsget user -dn -email
 
0
 
LVL 26

Expert Comment

by:Pber
ID: 22662468
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
 
0
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
LVL 26

Expert Comment

by:Pber
ID: 22662505
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
0
 
LVL 4

Author Comment

by:every1isevil2
ID: 22662542
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.
0
 
LVL 4

Author Comment

by:every1isevil2
ID: 22662653
This did the trick thanks again!

dsquery group -name "#Part-time faculty" | dsget group -members | dsget user -display -email
0
 
LVL 26

Expert Comment

by:Pber
ID: 22662694
glad to help.
0
 

Expert Comment

by:klfinkley
ID: 37458207
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  
0
 

Expert Comment

by:klfinkley
ID: 37458249
C:\>dsquery group -name "staff" | dsget group -members | dsget user -display -em
ail >c:\Staff.txt
dsget failed:The parameter is incorrect.
0
 
LVL 26

Expert Comment

by:Pber
ID: 37461278
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  
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
Active Directory security has been a hot topic of late, and for good reason. With 90% of the world’s organization using this system to manage access to all parts of their IT infrastructure, knowing how to protect against threats and keep vulnerabil…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question