Solved

using AD dsquery, I need a user list with group membership piped to a file.

Posted on 2008-10-10
3
5,928 Views
Last Modified: 2013-12-24
I am trying to use the cmd line for dsquery | dsget. The ultimates results that will be useful to me is 1. the user 2. what groups it is a member of. I have tried:
dsquery user "ou=users,ou=SubOU,dc=domain,dc=com" -o dn | dsget user -memberof > Z:\users.txt
*this gives me the groups, but I can't tell which user it belong to.

dsquery user "ou=users,ou=SubOU,dc=domain,dc=com" -o dn | dsget user -display > z:\users.txt
*this one shows all the users in the OU, but no group membership!

I need something like
User1
 - group1
 - group2
User2
 - group1
 - group3
 - group4
User3
 - group2
 - group3
 - group5
etc...

If possible, I'd like to do this from the command line using dsquery and dsget.
thanks in advance.
0
Comment
Question by:DESIGNUTT
  • 2
3 Comments
 
LVL 38

Accepted Solution

by:
Shift-3 earned 250 total points
ID: 22688397
Paste the script below into a text file with a .cmd extension.  Customize the value of the ou variable with the desired OU.  Running the script will echo the users and groups to the file users.txt.


@echo off

setlocal
 

set ou="ou=users,ou=SubOU,dc=domain,dc=com"
 

for /F "tokens=*" %%G in ('dsquery user %ou%') do (

 echo %%G >> users.txt

 for /F "tokens=*" %%H in ('dsget user %%G -memberof') do echo - %%H >> users.txt

)

Open in new window

0
 

Author Comment

by:DESIGNUTT
ID: 22703263
Thank you for the reply. I ran your script, I get 2 outputs (one of them for users, one of them for groups). Now, how do I match them up? I would like to show which user is a member of which of the groups. thanks for all the assistance.
0
 

Author Closing Comment

by:DESIGNUTT
ID: 31505017
I reran this script. This is what I needed. Thanks so much!! You made my day a little easier.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Creating and Managing Databases with phpMyAdmin in cPanel.
Disabling the Directory Sync Service Account in Office 365 will stop directory synchronization from working.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
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…

708 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

15 Experts available now in Live!

Get 1:1 Help Now