Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2008-10-10
3
Medium Priority
?
6,057 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
[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
  • 2
3 Comments
 
LVL 38

Accepted Solution

by:
Shift-3 earned 1000 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

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!

Question has a verified solution.

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

This process allows computer passwords to be managed and secured without using LAPS. This is an improvement on an existing process, enhanced to store password encrypted, instead of clear-text files within SQL
A bad practice commonly found during an account life cycle is to set its password to an initial, insecure password. The Password Reset Tool was developed to make the password reset process easier and more secure.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

705 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