Solved

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

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
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.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

752 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