Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

DSQUERY FOR USERS

Posted on 2009-07-13
6
Medium Priority
?
449 Views
Last Modified: 2013-11-10
I need a script that does the following:

-Generate a list of all users my domain and save to a text file
-It must NOT list the user account that have been disabled

I am not too concerned with how pretty the output file looks as I will use Excel to import it into a workbook.  So the following format is ok:
"CN=Charles Ross,CN=Users,DC=mogan,DC=local"

Open in new window

0
Comment
Question by:every1isevil2
[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
  • 5
6 Comments
 
LVL 20

Expert Comment

by:MightySW
ID: 24844035
Hi, you will need an AD export script.

Try this site:

http://www.visualbasicscript.com/m_29830/tm.htm

Copy the text and then save it as a .vbs file

They have a great example that will go to excel.

HTH
0
 
LVL 20

Expert Comment

by:MightySW
ID: 24844070
Wow, I just tried this.  It is AWESOME!  It will do everything you ask and more.  You can edit the fields as necessary.
0
 
LVL 20

Expert Comment

by:MightySW
ID: 24844105
Ok, I see you have the disabled disclaimer in there.  Let me see what I can do.
0
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 
LVL 4

Author Comment

by:every1isevil2
ID: 24844118
Thank you for the fast reply.

After looking at the code, which is quite nice, I am afraid that it does not meet either of my requirements.  I need it to send it to: a) text file and b) leave out disabled user accounts.

Please submit syntax/code.
0
 
LVL 20

Accepted Solution

by:
MightySW earned 2000 total points
ID: 24845062
Ok, here you go.

Just wrote it out and tested.

Works great.  You may want to remove the disabled = no column.  

What happens is the query looks for disable accounts being set to 'yes' and filters them with dsget.

HTH



@echo off & Setlocal EnableDelayedExpansion
title Users that have not changed their password for at least 80 days.
 
:: note, Useraccounts that are Disabled 
:: are filtered out and these users do not appear on the list. 
 
:: There is also a disabled column.  You can remove that as necessary
 
:: Set the strOU to your applicable domain name and root  (domain.com) would be DC=domain,DC=com  (no spaces)
 
:: Will send txt file to C:\getusers.txt.  
 
:: There is not a limit on this query.
 
Set "strOU=DC=FQDN_DOMAIN_NAME_Suffix,DC=com"
 
echo/QUERYING (incl. sub-OUs):
echo/%strOU%
echo/
 
Set /a iCnt=0
For /f "skip=1 delims=" %%a in ( 
	'dsquery.exe user "%strOU%" -name * -limit 0 -stalepwd 0 ^| dsget user -disabled -dn ^|Findstr /iv "\<yes\>" ^|Findstr /iv "\<dsget\>" ^> c:\getUsers.txt'
	) DO (
   	echo %%a 
    	)
 
echo/&echo/&echo/finished.&pause>nul

Open in new window

0
 
LVL 20

Expert Comment

by:MightySW
ID: 24845067
Its actually set for stalepassword of 0, so it will get everybody.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Introduction to Processes
Suggested Courses

610 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