Solved

DSQUERY FOR USERS

Posted on 2009-07-13
6
444 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
  • 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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 500 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
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…

808 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