?
Solved

Script to show all users whose password has expired.

Posted on 2008-11-18
16
Medium Priority
?
675 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:bsharath
  • 9
  • 6
16 Comments
 
LVL 11

Author Comment

by:bsharath
ID: 22996276
But these do not show which user has its password expired?
0
 
LVL 50

Accepted Solution

by:
Dave Brett earned 2000 total points
ID: 23013559
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 11

Author Comment

by:bsharath
ID: 23039406
When i run this script nothing happens no results.
0
 
LVL 11

Author Comment

by:bsharath
ID: 23039407
When i run this script nothing happens no results.
0
 
LVL 50

Expert Comment

by:Dave Brett
ID: 23040953
Nothing in the csv file?

c:\alluserspassword.csv
0
 
LVL 11

Author Comment

by:bsharath
ID: 23042436
No Dave it does not create a csv at all
0
 
LVL 50

Expert Comment

by:Dave Brett
ID: 23043111
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
 
LVL 11

Author Comment

by:bsharath
ID: 23049273
Still does not create. Even the wscript process does not start
0
 
LVL 11

Author Comment

by:bsharath
ID: 23049274
Still does not create. Even the wscript process does not start
0
 
LVL 50

Expert Comment

by:Dave Brett
ID: 23049298
... its Excel VBA
0
 
LVL 11

Author Comment

by:bsharath
ID: 23050699
Should i use the code in a excel?
Module?
0
 
LVL 50

Expert Comment

by:Dave Brett
ID: 23050749
Yep, try a normal module
0
 
LVL 11

Author Comment

by:bsharath
ID: 23077433
Thank U Dave...
0
 
LVL 50

Expert Comment

by:Dave Brett
ID: 23077488
Thx Sharath - so you got it working?

Cheers

Dave
0
 
LVL 11

Author Comment

by:bsharath
ID: 23077558
yes Dave it worked from within the excel when executed...
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses
Course of the Month14 days, 17 hours left to enroll

839 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