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
--