Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VBS to export password expiration into text files

Posted on 2010-09-13
8
Medium Priority
?
1,068 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 2000 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 2000 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

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

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

A hard and fast method for reducing Active Directory Administrators members.
A bad practice commonly found during an account life cycle is to set its password to an initial, insecure password. The Password Reset Tool was developed to make the password reset process easier and more secure.
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 …
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Suggested Courses

972 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