Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 916
  • Last Modified:

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>"
            Wscript.Quit
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
                        Else
                                    ObjTextFile.WriteLine objUser.sAMAccountName & ",0," & objUser.Info & "," & objUser.mail & "," & objuser.pwdLastSet & "," & objUser.userAccountControl
                        End If
            End if
Next

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



0
NTGuru705
Asked:
NTGuru705
1 Solution
 
exx1976Commented:
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)
wscript.echo(LastSet)
 
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

0

Featured Post

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now