Export AD usernames and login scripts used

Posted on 2007-11-16
Last Modified: 2012-06-27

I'm not sure if this is even possible but here goes.

I'm wanting to export ALL user names from our AD and the login script each user uses.  I'm trying to organize and determine which scripts are being utilized and which need to be deleted.  This is a 2003 sever environment.  If I can provide any additional information please let me know!
Question by:WVCA
LVL 48

Expert Comment

ID: 20298137
the DSTools should show you what you need.....i used it to similarly display profiles

Accepted Solution

carcenea earned 500 total points
ID: 20298793
Here is the code a a VBscript that will do what you want. All you should have to is change "dc=domain,dc=com" to "dc=yourdomain,dc=com". It will export all user's info into a textfile - userinfo.txt. There are a few extra fields as I've used this in the past for my own means.

Hope this helps!

Oh, and if you're not familiar with vbscript just put this code in a textfile and save the textfile with a .vbs for the extension.
' ListUsersOU.vbs

' Pulls specific info from each user in the domain and puts the info in a txtfile

' Author Chris 

' Created 10/31/2007

'Global variables

    Dim oContainer

    Dim OutPutFile

    Dim FileSystem

    Dim MyDate

'Set Date so that txt file can be unique

MyDate = Date()

MyDate = Replace(MyDate, "/", "-")

'Initialize global variables

    Set FileSystem = WScript.CreateObject("Scripting.FileSystemObject")

    Set OutPutFile = FileSystem.CreateTextFile("UserInfo" & MyDate & ".txt", True)

    Set oContainer = GetObject("LDAP://dc=domain,dc=com")

oContainer.Filter = Array("organizationalUnit")

strList = ""

'Enumerate Container

    EnumerateUsers oContainer

'Clean up


    Set FileSystem = Nothing

    Set oContainer = Nothing

    Set MyDate = Nothing

    'The line below is for testing purposes only.

    'WScript.Echo "Finished"


Sub EnumerateUsers(oCont)

    Dim oUser

    For Each oUser In oCont

        On Error Resume Next

        Select Case LCase(oUser.Class)

               Case "user"

                    If Not IsEmpty(oUser.distinguishedName) Then

                       OutPutFile.WriteLine "DisplayName: " & oUser.displayName

                       OutPutFile.WriteLine "Logon Name: " & oUser.sAMAccountName

                       OutPutFile.WriteLine "Phone Number: " & oUser.telephoneNumber

                       OutPutFile.WriteLine "Office: " & oUser.physicalDeliveryOfficeName

                       OutPutFile.WriteLine "Description: " & oUser.description

                       OutPutFile.WriteLine "Login Script: " & oUser.scriptPath


                    End If

               Case "organizationalunit", "container"

               EnumerateUsers oUser

        End Select


End Sub

Open in new window


Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
romain user profiles for windows users 22 64
vCenter 6 join Active Directory 6 74
New server 2016 DC in 2008 domain 4 44
exchange, active directory 8 32
[b]Ok so now I will show you how to add a user name to the description at login. [/b] First connect to your DC (Domain Controller / Active Directory Server) SET PERMISSIONS FOR SCRIPT TO UPDATE COMPUTER DESCRIPTION TO USERNAME 1. Open Active …
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now