'****************************************************************************** ' user_groups.vbs ' - lists all USER accounts and the USER GROUPS they belong to ' - lists all USER Groups defined on the local machine ' Requires ADSI ' http://msdn.microsoft.com/library/default.asp?url=/library/en-us/netdir/adsi/listing_users.asp ' ' M. Gallant 06/02/2002 ' ****************************************************************************** Option Explicit Dim myComputer, myComputer1, computername Dim member, grouptext, usergroup, property Dim WshShell, userClass Dim verbose : verbose=False 'Check if launched with Cscript host; if not, relaunch If (NOT InStr(UCase(WScript.FullName), "CSCRIPT") <> 0) Then Set WshShell = WScript.CreateObject("WScript.Shell") WshShell.Run "CScript.exe " & """" & WScript.ScriptFullName & """" WScript.Quit ' Terminate script. End If If WScript.Arguments.Count>0 Then If LCase(WScript.Arguments(0)) = "v" Then Verbose = True ElseIf LCase(WScript.Arguments(0)) = "u" OR LCase(WScript.Arguments(0)) = "?" Then Usage WScript.Quit End If End If computername = WScript.CreateObject("WScript.Network").ComputerName Set myComputer = GetObject("WinNT://" & computername & ",computer") Set myComputer1 = GetObject("WinNT://" & computername & ",computer") myComputer1.Filter = Array("group") WScript.Echo "------- USER accounts on this computer: " & computername & " -------" & vbCrLf myComputer.Filter = Array("user") For Each member In myComputer grouptext = "" For Each usergroup In myComputer1 'discover group membership If usergroup.IsMember(member.ADsPath) Then grouptext = grouptext & " " & usergroup.Name End If Next WScript.Echo member.Name &" [" & grouptext & "]" If Verbose = True Then Set userClass = GetObject(member.Schema) On Error Resume Next For Each property In userClass.OptionalProperties WScript.Echo " " & property & " " & member.Get(property) Next WScript.Echo Set userclass = nothing End If Next WScript.Echo vbCrLf WScript.Echo "------- USER GROUPS on this computer: " & computername & " -------" myComputer.Filter = Array("group") For Each member In myComputer WScript.Echo member.Name &": " & vbCrLf & member.Description & vbCrLf Next WScript.StdIn.ReadLine 'if launched by wscript or double-clicking, allow view of window Sub Usage() WScript.Echo "---- users_groups.vbs -----" WScript.Echo " cscript.exe users_groups.vbs " WScript.Echo " Verbose mode lists all supported OptionalProperties of the userclass" End Sub