'Comment. This script will prompt for a PC name and display a menu from which you : ' 1. List all members of local groups on the PC ' 2. Add a domain user to a local group. ' 3. Delete an user from a local group. ' 4. Reset remote PC's local Admin account's password. ' 5. Create a local group ' 6. Delete a local group 'Initialise arrays for user/group names dim memname(100,4) dim grpname(100) dim membersadmin Dim computername On Error Resume Next computername=" " Do While not computername="" computername=inputbox("Enter Machine Name - eg pcname"&vbcrlf&"Leave name blank or press Cancel to Exit","Target Machine","") if computername<>"" then Set Computer = GetObject("WinNT://" & computername) If Err Then HandleErr() Err.Clear end if set testgrp = GetObject("WinNT://" & Computername & "/administratoren,group") If Err Then HandleErr() Err.Clear else CNAME=ucase(Computername) DomADSpos=instr(computer.adspath,CNAME) DomADS=left(computer.adspath,DomADSpos-1) choice = 1 do while choice <> 0 choice = inputbox("Enter Choice"&vbcrlf&vbcrlf&"1. List Local Groups' Memberships."&vbcrlf&_ "2. Add to LG Memberships."&vbcrlf&"3. Delete LG Memberships."&vbcrlf&_ "4. Reset Local Admin Password."&vbcrlf&"5. Create Groups on Remote PC."&vbcrlf&_ "6. Delete Groups on Remote PC"&vbcrlf&"7.Exit","Manage "&Computername,0) if isnumeric(choice) then select case choice case 1 call GetListedgroups() msgbox membersadmin,0,computername&" Local Group Members" case 2 'Add members call GetListedgroups() choice2=1 Do While not choice2=0 choice2=inputbox("Type the number of the Group to which you wish to add domain members."&vbcrlf&vbcrlf&vbcrlf&membersadmin,computername&" Local Group Members",0) if choice2<> 0 then Set GroupObj = GetObject("WinNT://" & computername & "/"&grpname(choice2-1)) addchoice=inputbox("Type the name(s) of the Group(s)/User(s) you wish to add to "&grpname(choice2-1)&_ " - separated by commas. EG jsmith,Domain admins etc.",,"") 'Accepts comma-delimited list namearray=split(addchoice,",") ub=ubound(namearray) for arrvar=0 to ub addchoice=DomADS&namearray(arrvar) GroupObj.add(addchoice) next set GroupObj=nothing call GetListedgroups() end if loop case 3 'Delete Members call GetListedMembers() choice2=1 Do While not choice2=0 choice2=inputbox("Type the number(s) of the user(s)/group(s) you wish to delete from a local group."&vbcrlf&_ "You may enter a series of numbers separated by commas."&_ vbcrlf&membersadmin,computername&" Local Group Members",0) if choice2<> 0 then numarray=split(choice2,",") ub=ubound(numarray) for arrvar=0 to ub arrvar2=cint(arrvar) Set GroupObj = GetObject("WinNT://" & computername & "/"&memname(numarray(arrvar2)-1,1)) ch3=msgbox ("Delete "&memname(numarray(arrvar2)-1,0) &" from "&memname(numarray(arrvar2)-1,1)&"?",1,"Delete Member?") if ch3=1 then GroupObj.Remove(memname(numarray(arrvar2)-1,2)) end if set GroupObj=nothing next call GetListedMembers() end if loop case 4 'Change Remote Admin Password set usr = GetObject("WinNT://" & computername & "/administrator,user") newpassword=inputbox("Enter New Password","New Password",newpassword) if newpassword <>"" then usr.SetPassword newpassword If Err Then HandleAccessErr() Err.Clear else usr.SetInfo wscript.echo "Administrator password on "&computername& " set to "&newpassword&"." end if else wscript.echo "Password not changed on "&computername&"." end if set usr = nothing case 5 'Create Groups on remote PC call GetListedgroups() choice2=" " Do While not choice2="" choice2=inputbox("Type the name of the Group(s) you wish to add, separated by commas."&vbcrlf&vbcrlf&membersadmin,computername&" Local Group Members","") if choice2<> "" then namearray=split(choice2,",") ub=ubound(namearray) for arrvar=0 to ub Set Groupobj = Computer.Create("Group", namearray(arrvar)) Groupobj.Put "groupType", 4 Groupobj.Setinfo next set GroupObj=nothing call GetListedgroups() end if loop case 6 ' Delete Groups on remote PC call GetListedgroups() choice2=" " Do While not choice2="" choice2=inputbox("Type the number of the Group(s) you wish to delete on "&computername&". Separate Multiple numbers with commas."&vbcrlf&vbcrlf&vbcrlf&membersadmin,computername&" Local Group Members","") if choice2<> "" then numarray=split(choice2,",") ub=ubound(numarray) for arrvar=0 to ub arrvar2=cint(arrvar) 'make sure the input is an integer. ch3=msgbox ("Delete "&grpname(numarray(arrvar2)-1) &" from "&computername,1,"??") if ch3=1 then Computer.Delete "Group", grpname(numarray(arrvar2)-1) end if next call GetListedgroups() end if loop case 7 'Exit choice=0 end select end if loop end if end if loop Set Computer=nothing set testgrp = nothing sub GetListedGroups() membersadmin="" Computer.Filter = Array("Group") y=1 z=0 w=0 For Each Group in Computer x=0 membersadmin=membersadmin&y&". "&group.name memberstxt="" For each UserObj in Group.Members if Err then HandleAccessErr() Err.Clear else memberstxt=memberstxt&vbtab&UserObj.Name& " (" & UserObj.Class& ")"&vbcrlf x=x+1 end if Next if x=0 then membersadmin=membersadmin&vbtab&"No Members"&vbcrlf else membersadmin=membersadmin&vbcrlf&memberstxt end if grpname(y-1)=group.name y=y+1 x=x+1 Next end sub sub GetListedMembers() membersadmin="" Computer.Filter = Array("Group") y=1 z=0 w=0 For Each Group in Computer x=0 x=0 membersadmin=membersadmin&group.name memberstxt="" For each UserObj in Group.Members if Err then HandleAccessErr() Err.Clear else memberstxt=memberstxt&vbtab&y&". "&UserObj.Name& " (" & UserObj.Class& " )"&vbcrlf memname(y-1,0)=UserObj.Name memname(y-1,1)=group.name memname(y-1,2)=UserObj.ADsPath memname(y-1,3)=UserObj.Class x=x+1 y=y+1 end if Next if x=0 then membersadmin=membersadmin&vbtab&"No Members"&vbcrlf else membersadmin=membersadmin&vbcrlf&memberstxt end if Next end sub Sub WriteGrouplist() Computer.Filter = Array("Group") y=1 z=0 w=0 For Each Group in Computer x=0 For each UserObj in Group.Members if Err then HandleAccessErr() Err.Clear exit for else end if Next if x=0 then membersadmin=membersadmin&vbtab&"No Members"&vbcrlf else membersadmin=membersadmin&vbcrlf&memberstxt end if Next end sub sub HandleAccessErr() Wscript.echo "You have no administrative access to "&computername&"'s users." end sub Sub HandleErr() Wscript.echo computername&" is not responding to remote access." End Sub