Thursday, October 16, 2008

List Users and User Properties in a Given Domain (ADSI/VBScript)

List Users and User Properties in a Given Domain (ADSI/VBScript)

Author: Francis Danta
Category: Windows 2000/XP
Type: Snippets
Difficulty: Beginning

Version Compatibility: Visual Basic.NET VB Script/HTML

More information: List all users and some of their properties in a Windows 2000 AD domain or Windows NT4 domain. If domain is a computer, all users of the local SAM database are displayed.

This code has been viewed 93596 times.

Instructions: Copy the declarations and code below and paste directly into your VB project.


' ****************************************************************************
' List all users and some of their properties in a Windows 2000 AD domain or
' Windows NT4 domain. If domain is a computer, all users of the local SAM
' database are displayed.
' ****************************************************************************
' Goto http://www.activxperts.com/activmonitor and click on ADSI Samples
' for more samples
' ****************************************************************************

Sub ListUsers( strDomain )
Set objComputer = GetObject("WinNT://" & strDomain )
objComputer.Filter = Array( "User" )
For Each objUser In objComputer
WScript.Echo "Name: " & objUser.Name
WScript.Echo "Fullname: " & objUser.Fullname
WScript.Echo "Description: " & objUser.Description
WScript.Echo "AccountDisabled: " & objUser.AccountDisabled
WScript.Echo "IsAccountLocked: " & objUser.IsAccountLocked
WScript.Echo "Profile: " & objUser.Profile
WScript.Echo "LoginScript: " & objUser.LoginScript
WScript.Echo "HomeDirectory: " & objUser.HomeDirectory
WScript.Echo ""

Next
End Sub


' ****************************************************************************
' Main
' ****************************************************************************
Dim strDomain
Do
strDomain = inputbox( "Please enter a domainname", "Input" )
Loop until strDomain <> ""

ListUsers( strDomain )


WScript.Echo( vbCrlf & "For more samples, goto http://www.activxperts.com/activmonitor and click" )
WScript.Echo( "on ADSI samples" )

No comments: