Here's a nice script for getting domain users information and exporting it to a text file.
This script retrieve the following info:
- Display Name
- Username
- Logonscript
- Account Status
The account status retrives "code numbers" so here the translation of the codes:
- 514 | Disabled Account
- 546 | Disabled, Password Not Required
- 66050 | Disabled, Password Doesn't Expire
- 66082 | Disabled, Password Doesn't Expire & Not Required
- 262658 | Disabled, Smartcard Required
- 262690 | Disabled, Smartcard Required, Password Not Required
- 328194 | Disabled, Smartcard Required, Password Doesn't Expire
- 328226 | Disabled, Smartcard Required, Password Doesn't Expire & Not Required
And now, the script:
'**********************************************************************
' Application: Get Domain Users Information
'
' Overview: Get's the following information from domain users:
' - Display Name
' - Username
' - Logonscript
' - Account Status
'
' Author: FrontSlash Blog (http://www.front-slash.blogspot.com)
'**********************************************************************
'-------------------------------------------------------------------------'
' Variables Declaration '
'-------------------------------------------------------------------------'
Dim oContainer
Dim OutPutFile
Dim FileSystem
Dim MyDate
'-------------------------------------------------------------------------'
' Variables And Objects Initialization '
'-------------------------------------------------------------------------'
MyDate = Date()
MyDate = Replace(MyDate, "/", "-")
Set FileSystem = WScript.CreateObject("Scripting.FileSystemObject")
Set OutPutFile = FileSystem.CreateTextFile("DomainUsers" & MyDate & ".txt", True)
Set oContainer = GetObject("LDAP://dc=your,dc=domain,dc=here")
oContainer.Filter = Array("organizationalUnit")
strList = ""
'-------------------------------------------------------------------------'
' MAIN '
'-------------------------------------------------------------------------'
'Enumerate Container
EnumerateUsers oContainer
'Clean up
OutPutFile.Close
Set FileSystem = Nothing
Set oContainer = Nothing
Set MyDate = Nothing
'The line below is for testing purposes only.
'WScript.Echo "Finished"
WScript.Quit(0)
'Functions
'EnumerateUsers
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 oUser.displayName & ";" & oUser.sAMAccountName & ";" & oUser.scriptPath & ";" & oUser.userAccountControl
End If
Case "organizationalunit", "container"
EnumerateUsers oUser
End Select
Next
End Sub
Enjoy it! ;)