Solved

VBS to export password expiration into text files

Posted on 2010-09-13
8
1,056 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
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
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

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.

Question has a verified solution.

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

Issue: One Windows 2008 R2 64bit server on the network unable to connect to a buffalo Device (Linkstation) with firmware version 1.56. There are a total of four servers on the network this being one of them. Troubleshooting Steps: Connect via h…
This article explains the steps required to use the default Photos screensaver to display branding/corporate images
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 …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

821 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