Windows Vista Forums

Look up when password was last set
  1. #1


    Joe V Guest

    Look up when password was last set

    Hello,

    I'm writing a script to look up user account info from AD and I'm
    having a problem with getting when the password was last set.
    ------------
    'On Error Resume Next
    strUsername = "username"
    Const ADS_SCOPE_SUBTREE = 2

    Set objConnection = CreateObject("ADODB.Connection")
    Set objCommand = CreateObject("ADODB.Command")
    objConnection.Provider = "ADsDSOObject"
    objConnection.Open "Active Directory Provider"
    Set objCommand.ActiveConnection = objConnection

    objCommand.Properties("Page Size") = 1000
    objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE



    objCommand.CommandText = "SELECT Name, whenCreated, pwdLastSet FROM
    'LDAP://dc=corp,dc=acme,dc=local' WHERE objectCategory='user' " & "AND
    sAMAccountName='" & strUsername & "'"
    Set objRecordSet = objCommand.Execute

    objRecordSet.MoveFirst
    Do Until objRecordSet.EOF
    Wscript.Echo "Name: " & objRecordSet.Fields("Name").Value
    Wscript.Echo "Created: " &
    objRecordSet.Fields("whenCreated").Value
    Wscript.Echo "Pasword set: " &
    objRecordSet.Fields("pwdLastSet").Value
    objRecordSet.MoveNext
    Loop
    ------------------------------------

    Name and whenCreated come up just fine. But pwdLastSet I get an
    error.
    Line: 21, Char: 5, Error: Object doesn't support this property method,
    Code: 800A01B6

    Anyone know why I'm getting this error?

    Thanks,
    Joe

      My System SpecsSystem Spec

  2. #2


    Richard Mueller [MVP] Guest

    Re: Look up when password was last set

    Joe V wrote:

    > I'm writing a script to look up user account info from AD and I'm
    > having a problem with getting when the password was last set.
    > ------------
    > 'On Error Resume Next
    > strUsername = "username"
    > Const ADS_SCOPE_SUBTREE = 2
    >
    > Set objConnection = CreateObject("ADODB.Connection")
    > Set objCommand = CreateObject("ADODB.Command")
    > objConnection.Provider = "ADsDSOObject"
    > objConnection.Open "Active Directory Provider"
    > Set objCommand.ActiveConnection = objConnection
    >
    > objCommand.Properties("Page Size") = 1000
    > objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
    >
    > objCommand.CommandText = "SELECT Name, whenCreated, pwdLastSet FROM
    > 'LDAP://dc=corp,dc=acme,dc=local' WHERE objectCategory='user' " & "AND
    > sAMAccountName='" & strUsername & "'"
    > Set objRecordSet = objCommand.Execute
    >
    > objRecordSet.MoveFirst
    > Do Until objRecordSet.EOF
    > Wscript.Echo "Name: " & objRecordSet.Fields("Name").Value
    > Wscript.Echo "Created: " &
    > objRecordSet.Fields("whenCreated").Value
    > Wscript.Echo "Pasword set: " &
    > objRecordSet.Fields("pwdLastSet").Value
    > objRecordSet.MoveNext
    > Loop
    > ------------------------------------
    >
    > Name and whenCreated come up just fine. But pwdLastSet I get an
    > error.
    > Line: 21, Char: 5, Error: Object doesn't support this property method,
    > Code: 800A01B6
    >
    > Anyone know why I'm getting this error?
    The problem is that pwdLastSet is datatype Integer8, a 64-bit number
    representing the date. I have an example VBScript program that converts
    pwdLastSet (or any Integer8 value) to a date in the local time zone linked
    here:

    http://www.rlmueller.net/Programs/Integer8Date.txt

    When you use ADO to retrieve values, you need to use the Set keyword and the
    Value method of the ADO Fields collection to invoke the IADsLargeInteger
    interface. For example:

    Do Until adoRecordset.EOF

    Set objDate = adoRecordset.Fields("pwdLastSet").Value

    ' Use the Integer8Date function documented in the link above.

    dtmDate = Integer8Date(objDate, lngTZBias)

    Wscript.Echo "Password last set: " & dtmDate

    adoRecordset.MoveNext
    Loop



    where lngTZBias is the local time zone bias in minutes and Integer8Date is
    the function in the link above. If lngTZBias is zero, the date/time value is
    in UTC (Coordinated Universal Time, or what used to be called GMT).


    --
    Richard Mueller
    MVP Directory Services
    Hilltop Lab - http://www.rlmueller.net
    --



      My System SpecsSystem Spec

  3. #3


    Joe V Guest

    Re: Look up when password was last set

    Richard,

    That worked, thanks.

    Joe

      My System SpecsSystem Spec

Look up when password was last set problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can not reset admin password under safe mode due to password policy? john Vista security 1 26 Jan 2010
Forgot e-mail password; messed-up Live password reset...account disabled and in limbo.... kaydianne Vista mail 1 04 Jul 2009
Privision User must change password at next logon, if passwordchanged, set password never expire klam10411 VB Script 1 02 Apr 2009
*!NOT your usual Vista Password Problem - Incorrect Password even every time even after resetting fvuong Vista account administration 33 25 Mar 2009
backup to a network drive is asking for username and password...whatusername and password? Lisa Hetherington Vista General 7 04 Feb 2008