Solved

VBS to export password expiration into text files

Posted on 2010-09-13
8
1,059 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Last week, our Skyport webinar on “How to secure your Active Directory” (https://www.experts-exchange.com/videos/5810/Webinar-Is-Your-Active-Directory-as-Secure-as-You-Think.html?cid=Gene_Skyport) provided 218 attendees with a step-by-step guide for…
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
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…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

751 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