Solved

VBS to export password expiration into text files

Posted on 2010-09-13
8
1,050 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Do email signature updates give you a headache?

Do you feel like all of your time is spent managing email signatures? Too busy to visit every user’s desk to make updates? Want high-quality HTML signatures on all devices, including on mobiles and Macs? Then, let Exclaimer solve all your email signature problems today!

 
LVL 5

Expert Comment

by:MisterTwelve
Comment Utility
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
Comment Utility
this code search all domain and create Text file with
UserAccount ; Username ; ExperiesDate
0
 

Author Comment

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

Expert Comment

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

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
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 to another domain controller. Log onto the new domain controller with a user account t…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

744 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

13 Experts available now in Live!

Get 1:1 Help Now