Solved

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

Posted on 2008-10-10
3
5,937 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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

Read about achieving the basic levels of HRIS security in the workplace.
Disabling the Directory Sync Service Account in Office 365 will stop directory synchronization from working.
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 Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

911 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

23 Experts available now in Live!

Get 1:1 Help Now