Solved

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

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
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 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.

820 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