- For individual users
- Instant access to solutions
- Ask your tech questions
- Start your 30-day Free Trial
Main Topics
Browse All TopicsAnyone know what I'm doing wrong? I want to export the user accounts and last logon to an excel spreadsheet ... out of Active Directory ... below is a modified version of my script.
Thanks,
Brian
__________________________
'*************************
'** Created by Brian Nettles for User Last Login for CORP.Contoso.com **
'** This script exports the following fields: **
'** Username, Display Name, Last Login **
'** Each line is tab delimited to be used for the XLS format **
'*************************
'Global variables
Dim oContainer
Dim OutPutFile
Dim FileSystem
'Initialize global variables
Set FileSystem = WScript.CreateObject("Scri
Set OutPutFile = FileSystem.CreateTextFile(
OutPutFile.WriteLine "Username" & vbtab & "Display Name" & vbtab & "Last Logon Timestamp"
Set oContainer = GetObject("LDAP://OU=Accou
'Enumerate Container
EnumerateUsers oContainer
'Clean up
OutPutFile.Close
Set FileSystem = Nothing
Set oContainer = Nothing
WScript.Echo "Finished"
WScript.Quit(0)
Sub EnumerateUsers(oCont)
Dim oUser, bUser
For Each oUser In oCont
bUser = False
Select Case LCase(oUser.Class)
Case "user"
' User Account Login
If Not IsEmpty(oUser.sAMAccountNa
If Not Instr(1,LCase(oUser.sAMAcc
If Not Instr(1,LCase(oUser.sAMAcc
If Not Instr(1,LCase(oUser.sAMAcc
bUser = True
OutPutFile.Write oUser.sAMAccountName & vbtab
' User Account Display Name
OutPutFile.Write oUser.displayName & vbtab
' User Account Last Logon Timestamp
OutPutFile.Write oUser.lastLogonTimestamp & vbtab
End If
End If
End If
End If
Case "organizationalunit", "container"
EnumerateUsers oUser
End Select
If bUser Then
OutPutFile.WriteLine
End If
Next
End Sub
This question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership