| Filesystem: VBscript to enumerate the subfolders (recursive) with depth limit | Active Directory: VBscript to enumerate the roaming profile size of all users in Active Directory |
This script is a further development of my previous lastlogon script.
Changes are: time bias with wmi, less code, array based attributes.
By adding extra attributes to the arrAttributes array you can expand the output.
Follow the next steps to run the script (no admin rights needed):
* open your favorite text editor
* copy and paste the script into the editor
* save the script (for example c:\temp\enumerate-lastlogon-details2.vbs)
* open a command prompt
* go to “c:\temp”
* give “cscript enumerate-lastlogon-details2.vbs” (without quotes) and enter
The script:
' Name : enumerate-lastlogon-details2.vbs
' Description : script to enumerate the last logon of all AD users and a lot of user attributes V2
' Author : dirk adamsky - deludi bv
' Version : 2.00
' Date : 12-03-2010
' Level : advanced
intBias = TimeZoneBias
arrAttributes = Array("lastLogonTimeStamp","displayname","mail")
Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnection = adoConnection
Set objRootDSE = GetObject("LDAP://RootDSE")
strBase = "<LDAP://" & objRootDSE.Get("defaultNamingContext") & ">"
Set objRootDSE = Nothing
strFilter = "(&(objectCategory=person)(objectClass=user))"
strAttributes = Join(arrAttributes,",")
Wscript.Echo Join(arrAttributes,";")
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
adoCommand.CommandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("Timeout") = 30
adoCommand.Properties("Cache Results") = False
Set adoRecordset = adoCommand.Execute
Do Until adoRecordset.EOF
On Error Resume Next
strTempOutput = ""
For i = 1 To Ubound(arrAttributes)
strTempOutput = strTempOutput & " ; " & adoRecordset.Fields(arrAttributes(i)).Value
strOutput = Mid(Ltrim(strTempOutput),3)
Next
Set objDate = adoRecordset.Fields(arrAttributes(0)).Value
If (Err.Number <> 0) Then
dtmDate = #1/1/1601#
Else
dtmDate = ((((objDate.Highpart * (2^32)) + objDate.LowPart)/(600000000 - intBias))/1440) + #1/1/1601#
End If
Set objDate = Nothing
Wscript.Echo strOutput & " ; " & dtmDate
adoRecordset.MoveNext
Loop
adoRecordset.Close
adoConnection.Close
Set adoRecordset = Nothing
Set adoConnection = Nothing
Set adoCommand = Nothing
Function TimeZoneBias
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colTimeZone = objWMIService.ExecQuery("Select * from Win32_TimeZone")
For Each objTimeZone in colTimeZone
TimeZoneBias = objTimeZone.Bias
Next
Set colTimeZone = Nothing
Set objWMIService = Nothing
End Function
When you have problems/questions please post a reply.
Happy scripting.
Best regards,
Dirk Adamsky – Deludi BV
VN:F [1.9.3_1094]
VN:F [1.9.3_1094]
Posted by dirk adamsky at 14:03
Tagged with: active directory, attribute, bias, command prompt, cscript, enumerate, lastlogon, lastlogontimestamp, list, number, user, vbs, vbscript, Win32_TimeZone, wmi





[...] by creating a script that was a combination of earlier scripts. The lastlogon code came from my lastlogon script, the enumeration of the group members code was taken from my enumeratenestedgroup script. The users [...]
[...] I made a new lastlogonscript, it can be found here. This script is based on the lastlogon script by Richard L. Mueller. Added is an enumeration of 30 [...]
Hi,
The other day I came across an equally helpful write up on True Last Logon and I thought I’d share it with you. By the way, there are free Active Directory Reporting Tools out there with which you can determine the true last logon of domain user and computer accounts. I thought I would share it with you in case it can help you as well.
Thanks,
Aaron
How can i get the AD users lastlogon details in Descending order. Please help on this.
Hi Manimaran,
You can do that either in the script or after running the script.
The latter is the easiest.
The steps:
1. save the script enumerate-lastlogon-details2.vbs in c:\temp
2. open a command prompt (no admin rights needed)
3. go to c:\temp
4. give “cscript enumerate-lastlogon-details2.vbs > lastlogon.txt” (without the quotes)
5. when the script is finished the result is a textfile called lastlogon.txt (in c:\temp)
6. start excel
7. open the textfile with excel
8. give a semi-column as field separator sign
9. you can now sort the data with excel
When you want to have more user data you can add user properties to the arrAttributes array.
Hope the above helps you finishing your work.
Best regards,
Dirk Adamsky