Solved

VBS to export password expiration into text files

Posted on 2010-09-13
8
1,053 Views
Last Modified: 2013-11-21
Hello,

I'm looking for a script that will input in a text files all the accounts located in a certain OU  with their expirarion date, it would be nice if we can know base on current date in how many days the account will expire.

thanks a lot !!!
0
Comment
Question by:brular01
  • 3
  • 3
  • 2
8 Comments
 
LVL 57

Accepted Solution

by:
Mike Kline earned 500 total points
ID: 33663042
You could use a tool like adfind from Joe Richards    http://www.joeware.net/freetools/tools/adfind/index.htm

adfind -b "DN of your OU"  -f "&(objectcategory=person)(ojbectclass=user)"  samaccountname accountexpires -tdcs -csv > c:\users.csv

Thanks

Mike
0
 

Author Comment

by:brular01
ID: 33663362
Hi,

It's not giving me any results and i know my DN of the OU is good
0
 
LVL 57

Assisted Solution

by:Mike Kline
Mike Kline earned 500 total points
ID: 33663640
wait a second horrible mistype by me  >>second object is misspelled
 
adfind -b "DN of your OU"  -f  "&(objectcategory=person)(objectclass=user)"  samaccountname accountexpires -tdcs -csv > c:\users.csv
if you want to test for the entire domain use afdind -default ....(rest is the same)
Thanks
Mike
0
 
LVL 57

Expert Comment

by:Mike Kline
ID: 33666445
Forget my answer, I'm pulling the account expires info which is not what you need.   You need a script like this   http://www.experts-exchange.com/Software/Server_Software/File_Servers/Active_Directory/Q_24487750.html
the account info add in can also show you the info in ADUC   http://www.computerperformance.co.uk/w2k3/utilities/acctinfo.htm
Thanks
Mike
0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 5

Expert Comment

by:MisterTwelve
ID: 33671280
This Code save to VBS.
change Domain

Regards

on error Resume Next





Const ForReading = 1, ForWriting = 2, ForAppending = 3

Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0

Dim fs, f, ts, s





Set fs = CreateObject("Scripting.FileSystemObject")

File = "d:\expiredateallusers.txt"

fs.CreateTextFile File

Set f = fs.GetFile(File)

Set ts = f.OpenAsTextStream(ForWriting, TristateFalse)







Set objConnection = CreateObject("ADODB.Connection")

objConnection.Open "Provider=ADsDSOObject;"



Set objCommand = CreateObject("ADODB.Command")

objCommand.ActiveConnection = objConnection



objCommand.CommandText = _

    "<GC://dc=DOMAIN,dc=LOCAL>;(&(objectCategory=user)(samaccountname=*))" & _

        ";name,samaccountname,AccountExpires,distinguishedname,displayname;subtree" 



objCommand.Properties("Page Size") = 1000

Set objRecordSet = objCommand.Execute

intCounter = 0

While Not objRecordset.EOF



'wscript.Echo objRecordSet.Fields("samaccountname") & " - " & objRecordSet.Fields("accountExpires")

ts.writeline  objRecordSet.Fields("samaccountname")& ";" & objRecordSet.Fields("name") & ";" & objRecordSet.Fields("accountExpires")



        objRecordset.MoveNext

      

Wend

Open in new window

0
 
LVL 5

Expert Comment

by:MisterTwelve
ID: 33671305
this code search all domain and create Text file with
UserAccount ; Username ; ExperiesDate
0
 

Author Comment

by:brular01
ID: 33698134
How can I only search on a specify OU and return all the users in the OU ?
0
 
LVL 5

Expert Comment

by:MisterTwelve
ID: 33699772
Change line
"<GC://dc=DOMAIN,dc=LOCAL>  ;
for this
<LDAP://OU=SecondOU,OU=FirstOU,DC=DOMAIN,DC=local>
Regards
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Mapping Drives using Group policy preferences Are you still using old scripts to map your network drives if so this article will show you how to get away for old scripts and move toward Group Policy Preference for mapping them. First things f…
Remote Apps is a feature in server 2008 which allows users to run applications off Remote Desktop Servers without having to log into them to run the applications.  The user can either have a desktop shortcut installed or go through the web portal to…
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

867 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now