VBScript LDAP Question

I am writing a small vbscript tool and have a question...

When I query using ldp my active directory server there is a propery on the user called pwdLastSet... I can see it just fine.
When I run this code I get that it isnt a valid property..

'Get Domain Information
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("DefaultNamingContext")
strContainer = "CN=Users ,"
'Check that filename was passed as argument
If Wscript.Arguments.Count = 0 Then
            Wscript.Echo "Usage: cscript ADExport.vbs <filename>"
End If
strFilename = WScript.Arguments(0)
'Open Text File for writing
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.CreateTextFile(strFilename, True)
strContainer = strContainer & strDNSDomain
set objOU =GetObject("LDAP://" & strContainer )
For each objUser in objOU
            If objUser.class="user" then
                        If objUser.userAccountControl = 514 Then
                                    ObjTextFile.WriteLine objUser.sAMAccountName & ",1," & objUser.Info & "," & objUser.mail & "," & objuser.pwdLastSet & "," & objUser.userAccountControl
                                    ObjTextFile.WriteLine objUser.sAMAccountName & ",0," & objUser.Info & "," & objUser.mail & "," & objuser.pwdLastSet & "," & objUser.userAccountControl
                        End If
            End if

So the question here is WHY cant I get to this property?

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.

That's because the value is stored as Integer8 (64-bit), not as a date.  You have to convert it.  The error you were getting was "Type Mismatch", right?

The code below should work for you.

Set oDate = objUser.pwdLastSet
LastSet = Integer8Date(oDate)
Function Integer8Date(ByVal objDate)
    lngHigh = objDate.HighPart
    lngLow = objdate.LowPart
    If (lngLow < 0) Then lngHigh = lngHigh + 1
    If (lngHigh = 0) And (lngLow = 0) Then lngAdjust = 0
    lngDate = #1/1/1601# + (((lngHigh * (2 ^ 32)) + lngLow) / 600000000 - lngAdjust) / 1440
    Integer8Date = CDate(lngDate)
End Function

Open in new window

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

From novice to tech pro — start learning today.