GaryB999
12-12-2002, 02:28 AM
Hi All,
I'm having a nightmare getting the following WSH script to return lastlogin values from our active directory.
On error resume Next
Dim oContainer
Dim oUser
Dim Lastlogon
set wshshell = CreateObject("Wscript.Shell")
set fso = CreateObject("Scripting.FileSystemObject")
'Get output filename
LDAPOutput = inputbox("Please state the path and filename for the LDAP Output? [MANDATORY]","LDAP output Details","C:\temp\LDAP_Extract.txt")
If LDAPOutput = "" then
MSGBOX "Exiting as no Output file declared!",vbOKonly
wscript.quit
End If
Set oContainer=GetObject("LDAP://CN=users,DC=colp,DC=co,DC=uk")
counter = 1
GetUsers(oContainer)
'cleanup
Set oContainer = Nothing
Msgbox "Completed compiling all domain users" & vbcr & vbcr & "Compiled " & counter & " records.", vbokonly
Function GetUsers(oObject)
oObject.Filter = Array("user")
For Each oUser in oObject
If oUser.lastlogin <> "" then
Lastlogon = oUser.lastLogin
Else
Lastlogon = "Unavailable"
End If
UserName = oUser.sAMAccountName
If oUser.sn <> "" then
Firstname = oUser.givenName
LastName = oUser.sn
Name = LastName & " " & Firstname
Else
Name = "Undefined"
End If
AppendFile Name, UserName, lastlogon
counter = counter + 1
Next
End Function
Sub AppendFile(oName, oUserName, oLastLogin)
set OutputFile = fso.opentextfile(LDAPOutput, 8, true)
outputfile.writeline oName & "," & oUserName & "," & oLastLogin
outputfile.close
End Sub
The script executes with error 35 'The active directory property cannot be found in the cache' and only returns 590 records from a total of 1750 !! Any suggestions gratefully received.
Festive thanks,
Gary
I'm having a nightmare getting the following WSH script to return lastlogin values from our active directory.
On error resume Next
Dim oContainer
Dim oUser
Dim Lastlogon
set wshshell = CreateObject("Wscript.Shell")
set fso = CreateObject("Scripting.FileSystemObject")
'Get output filename
LDAPOutput = inputbox("Please state the path and filename for the LDAP Output? [MANDATORY]","LDAP output Details","C:\temp\LDAP_Extract.txt")
If LDAPOutput = "" then
MSGBOX "Exiting as no Output file declared!",vbOKonly
wscript.quit
End If
Set oContainer=GetObject("LDAP://CN=users,DC=colp,DC=co,DC=uk")
counter = 1
GetUsers(oContainer)
'cleanup
Set oContainer = Nothing
Msgbox "Completed compiling all domain users" & vbcr & vbcr & "Compiled " & counter & " records.", vbokonly
Function GetUsers(oObject)
oObject.Filter = Array("user")
For Each oUser in oObject
If oUser.lastlogin <> "" then
Lastlogon = oUser.lastLogin
Else
Lastlogon = "Unavailable"
End If
UserName = oUser.sAMAccountName
If oUser.sn <> "" then
Firstname = oUser.givenName
LastName = oUser.sn
Name = LastName & " " & Firstname
Else
Name = "Undefined"
End If
AppendFile Name, UserName, lastlogon
counter = counter + 1
Next
End Function
Sub AppendFile(oName, oUserName, oLastLogin)
set OutputFile = fso.opentextfile(LDAPOutput, 8, true)
outputfile.writeline oName & "," & oUserName & "," & oLastLogin
outputfile.close
End Sub
The script executes with error 35 'The active directory property cannot be found in the cache' and only returns 590 records from a total of 1750 !! Any suggestions gratefully received.
Festive thanks,
Gary