'======================================================================================================== '======================================================================================================== ' ### Script: remotemembers.vbs ' ### ScriptVersion: 1 ' ### Created: 08/26/05 ' ### Group: AHS ' ### Contact: timcho@safeco.com ' ### Description: Lists all members of local groups on a remote server '======================================================================================================== '======================================================================================================== 'Option Explicit On Error Resume Next 'Set our variables Dim WshShell,Wshnetwork,Wshfile Dim strServer,strMember,strUser Dim strScriptName Dim objArgs Dim temp 'Set up our environment Set WshShell = WScript.CreateObject("WScript.Shell") Set Wshnetwork = wscript.CreateObject("Wscript.Network") Set Wshfile = wscript.CreateObject("Scripting.FileSystemObject") strScriptName = Left(wscript.ScriptName, InStr(1, wscript.ScriptName, ".vbs", 1) - 1) 'Check to ensure we're using cscript If InStr(1, wscript.fullname, "cscript.exe", 1) = 0 Then VerifyCscript 'Check for arguments Set objArgs = WScript.Arguments If objArgs.Count = 1 Then strServer = lcase(objArgs(0)) ELSE wscript.echo "" wscript.echo "Usage:" wscript.echo "remotemembers servername" wscript.echo "" wscript.echo "Example:" wscript.echo "remotemembers hoxeft01" wscript.echo "" wscript.echo "Lists all members of all local groups on a remote server." wscript.quit END IF if left(strServer,2) = "\\" then strServer = mid(strServer,3) wscript.echo "" Group_Query strServer '======================================================================================================== '======================================================================================================== Sub Group_Query(strServer) On error resume next Dim objGroup,User,objGroupMembers,Group,UserName set objGroup = GetObject("WinNT://" & strServer) IF err.number <> 0 THEN wscript.echo err.number & " " & err.description Exit Sub END IF objGroup.Filter = Array("Group") For each Group in objGroup wscript.echo Group.Name & " members:" set objGroupMembers = GetObject("WinNT://" & strServer & "/" & Group.Name & ",group") For each User in objGroupMembers.Members UserName = Replace(User.ADsPath,"WinNT://","") UserName = Replace(UserName,"/","\") wscript.echo "\\" & strserver & "\" & Group.Name & ":" & UserName Next wscript.echo "" Next END Sub '======================================================================================================== '======================================================================================================== Function VerifyCscript() Dim temp 'Sets up Vbscript to always run in command window temp = wshshell.Run("cmd /c ""wscript //h:cscript //nologo //s 1>nul 2>nul""", 0, true) temp = MsgBox ("The script has changed the default output of Windows Scripting Host to the command prompt." &_ vbCrLf & "This is pop up is normal, just re-run the script!", 0, "WSH default changed to cscript.") wscript.quit End Function '======================================================================================================== 'END OF SCRIPT '========================================================================================================