Solved

Need correct syntax for DSQUERY and DSGET operation.

Posted on 2008-10-07
10
1,181 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Disabling the Directory Sync Service Account in Office 365 will stop directory synchronization from working.
In this article, I am going to show you how to simulate a multi-site Lab environment on a single Hyper-V host. I use this method successfully in my own lab to simulate three fully routed global AD Sites on a Windows 10 Hyper-V host.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

786 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