Script to show all users whose password has expired.

Hi,

Script to show all users whose password has expired.
How can i get the names of the users whose passwords have expired.

Regards
Sharath
LVL 11
bsharathAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ggilioCommented:
0
bsharathAuthor Commented:
But these do not show which user has its password expired?
0
DaveCommented:
Sharath,

This excel VBA creates a file
c:\alluserspassword.csv
that lists all users who need to reset their password next time they logon

Does your company policy require all users to change their passwords at a set time interval, say 90 days? If this happened at the same time then an alternative method would be to check the date the password was last set to see if it fell outside this range

Cheers

Dave

 
 
Sub AllUsersNeedPasswordRest()
 
    Dim adoCommand, adoConnection, strBAse, strFilter, strAttributes
    Dim objRootDSE, strDNSDomain, strQuery, adoRecordset, strName, strCN
 
 
    ' Setup ADO objects.
    Set adoCommand = CreateObject("ADODB.Command")
    Set adoConnection = CreateObject("ADODB.Connection")
    adoConnection.Provider = "ADsDSOObject"
    adoConnection.Open "Active Directory Provider"
    adoCommand.ActiveConnection = adoConnection
 
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set userfile = fs.CreateTextFile("c:\alluserspassword.csv")
 
    Set objRootDSE = GetObject("LDAP://RootDSE")
 
    strDNSDomain = objRootDSE.Get("defaultNamingContext")
    strBAse = "<LDAP://" & strDNSDomain & ">"
 
    strFilter = "(&(objectCategory=person)(objectClass=user)(pwdLastSet=0))"
    ' Comma delimited list of attribute values to retrieve.
    strAttributes = "sAMAccountName,cn,distinguishedname"
 
    ' Construct the LDAP syntax query.
    strQuery = strBAse & ";" & strFilter & ";" & strAttributes & ";subtree"
    adoCommand.CommandText = strQuery
    adoCommand.Properties("Page Size") = 100
    adoCommand.Properties("Timeout") = 30
    adoCommand.Properties("Cache Results") = False
 
    Set adoRecordset = adoCommand.Execute
    Do Until adoRecordset.EOF
        strName = adoRecordset.Fields("sAMAccountName").Value
        strCN = adoRecordset.Fields("cn").Value
        strDN = adoRecordset.Fields("distinguishedname").Value
 
        userfile.write "NT Name: " & strName & ", Common Name " & strCN & ", Distinguished Name: " & strDN
        userfile.writeline
 
        adoRecordset.MoveNext
    Loop
 
    ' Clean up
 
    adoRecordset.Close
    adoConnection.Close
 
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

bsharathAuthor Commented:
When i run this script nothing happens no results.
0
bsharathAuthor Commented:
When i run this script nothing happens no results.
0
DaveCommented:
Nothing in the csv file?

c:\alluserspassword.csv
0
bsharathAuthor Commented:
No Dave it does not create a csv at all
0
DaveCommented:
as a test, pls test if the csv is created if you change

strFilter = "(&(objectCategory=person)(objectClass=user)(pwdLastSet=0))"
to
strFilter = "(&(objectCategory=person)(objectClass=user))"

Cheers

Dave
0
bsharathAuthor Commented:
Still does not create. Even the wscript process does not start
0
bsharathAuthor Commented:
Still does not create. Even the wscript process does not start
0
DaveCommented:
... its Excel VBA
0
bsharathAuthor Commented:
Should i use the code in a excel?
Module?
0
DaveCommented:
Yep, try a normal module
0
bsharathAuthor Commented:
Thank U Dave...
0
DaveCommented:
Thx Sharath - so you got it working?

Cheers

Dave
0
bsharathAuthor Commented:
yes Dave it worked from within the excel when executed...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Scripting Languages

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.