LastLogon VBS script error on dc,error-table does not exisit code 80040e37. line 41.char:9


hi, trying run vb script lastlogon information . tested on win2003 dc , works well. run on production win2003 dc server failed.with errorl table not exisit code 80040e37. line 41.char:9. source: provider. advice please?the script below.

option explicit
 
' global constants
 
const file_name = "lastlogon.csv"
 
'
' subroutines
'
 
sub getlastlogon(objdomaincontroller)
        const ads_scope_subtree = 2
        const ads_uf_accountdisable = &h2
 
        dim objconnection, objcommand, objrecordset, objrootdse, objlastlogon
        dim strdcname, strusername, strdn, strdisplayname
        dim intuac, intlogontime
        dim dtmlastlogon
 
        strdcname = mid(objdomaincontroller.name, 4, len(objdomaincontroller.name))
 
        set objconnection = createobject("adodb.connection")
        objconnection.provider = "adsdsoobject"
        objconnection.open "active directory provider"
        
        set objcommand = createobject("adodb.command")
        set objcommand.activeconnection = objconnection
        
        wscript.echo "querying: " & strdcname
        set objrootdse = getobject("ldap://rootdse")
        objcommand.commandtext = "select samaccountname, lastlogon, distinguishedname, useraccountcontrol, " &_
                "displayname 'ldap://" & strdcname & "/" & objrootdse.get("defaultnamingcontext") & "' " &_
                "where objectclass='user' , objectcategory='person'"
        set objrootdse = nothing
        
        objcommand.properties("page size") = 1000
        objcommand.properties("timeout") = 600
        objcommand.properties("searchscope") = ads_scope_subtree
        objcommand.properties("cache results") = false
 
        set objrecordset = objcommand.execute
        
        while not objrecordset.eof
                strusername = objrecordset.fields("samaccountname")
                strdn = objrecordset.fields("distinguishedname")
                intuac = objrecordset.fields("useraccountcontrol")
                on error resume next
                strdisplayname = "" : strdisplayname = objrecordset.fields("displayname")
                on error goto 0
 
                if intuac , ads_uf_accountdisable
                        straccountstate = "disabled"
                else
                        straccountstate = "enabled"
                end if
 
                on error resume next
                objlastlogon = objrecordset.fields("lastlogon")
 
                intlogontime = objlastlogon.highpart * (2^32) + objlastlogon.lowpart
                intlogontime = intlogontime / 600000000
                intlogontime = intlogontime / 1440
                dtmlastlogon = intlogontime + #01/01/1601#
 
                set objlastlogon = nothing
                on error goto 0
 
                if dtmlastlogon <> #01/01/1601#
                        if objusers.exists(strusername )
                                if dtmlastlogon > objusers(strusername)(0)
                                        objusers.remove(strusername)
                                        objusers.add strusername, array(dtmlastlogon, _
                                                straccountstate, strdn, strdisplayname)
                                end if
                        else
                                objusers.add strusername, array(dtmlastlogon, _
                                        straccountstate, strdn, strdisplayname)
                        end if
                end if
 
                objrecordset.movenext
        wend
 
        set objrecordset = nothing
        set objcommand = nothing
        set objconnection = nothing
end sub
 
'
' main code
'
 
dim objrootdse, objusers, objdomaincontrollers, objdomaincontroller, objfilesystem, objfile
dim strusername, straccountstate, strdn, strdisplayname
dim dtmlastlogon, dtmruntime
 
dtmruntime =
 
set objrootdse = getobject("ldap://rootdse")
 
set objusers = createobject("scripting.dictionary")
 
' dc list
 
set objdomaincontrollers = getobject("ldap://ou=domain controllers," &_
          objrootdse.get("defaultnamingcontext"))
objdomaincontrollers.filter = array("computer")
 
each objdomaincontroller in objdomaincontrollers
          getlastlogon objdomaincontroller
next
 
set objdomaincontrollers = nothing
set objrootdse = nothing
 
' reporting
 
set objfilesystem = createobject("scripting.filesystemobject")
set objfile = objfilesystem.createtextfile(file_name, true, false)
 
each strusername in objusers
        dtmlastlogon = objusers(strusername)(0)
        straccountstate = objusers(strusername)(1)
        strdn = objusers(strusername)(2)
        strdisplayname = objusers(strusername)(3)
 
        objfile.writeline """" & strdisplayname & """,""" & straccountstate & """,""" &_
                dtmlastlogon & """,""" & strusername & """,""" & strdn & """"
next
 
wscript.echo "run time: " & datediff("s", dtmruntime, now) & " seconds"
 
objfile.close
set objfilesystem = nothing
 
set objusers = nothing

if helps, have vbscript , can download at:
http://www.pbbergs.com/windows/downloads.htm
select "active directory user account attributes"

--
paul bergson
mvp - directory services
mcitp: enterprise administrator
mcts, mct, mcse, mcsa, security+, bs csci
2008, vista, 2003, 2000 (early achiever), nt4
http://www.pbbergs.com    twitter @pbbergs
http://blogs.dirteam.com/blogs/paulbergson

please no e-mails, questions should posted in newsgroup. this
posting provided "as is" no warranties, , confers no rights.



Windows Server  >  Directory Services



Comments

Popular posts from this blog

WIMMount (HSM) causing cluster storage to go redirected (2012r2 DC)

Failed to delete the test record dcdiag-test-record in zone test.com

Azure MFA with Azure AD and RDS