Solved

Need correct syntax for DSQUERY and DSGET operation.

Posted on 2008-10-07
10
1,178 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
  • 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
 
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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
active directory 1 40
Computer software inventory 5 36
Powershell - check csv format 4 31
Index Details in SQL Server 2012 4 11
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now