script to add multple users to local admin group on servers



Can someone please correct me if I am doing anything wrong.

The script should read 2 files

users.txt - list of domain users
hosts.txt - list of hosts

It will read the users.txt and add the users as local admins to all the
hosts in host.txt

----------------------------------------------------------------------------------------


' Script to add domain user to local administrators group

Option Explicit

Dim objNetwork, strDomain, strComputer, strFilename
Dim strUser, objUser, objGroup, objFSO, objTextStream
Dim StrUserFilename


Const FOR_READING = 1


' Open text file of computer names.

strFilename = "c:\scripts\hosts.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextStream = objFSO.OpenTextFile(strFilename, FOR_READING)
set objNetwork = CreateObject("Wscript.Network")
strDomain = objNetwork.UserDomain


' Open text file of user names

strUserFilename = "c:\scripts\users.txt
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextStream = objFSO.OpenTextFile(strFilename, FOR_READING)
set objNetwork = CreateObject("Wscript.Network")
strDomain = objNetwork.UserDomain
'Set objUser = GetObject("WinNT://" & strDomain & "/" & strUser & ",user")



' Read text file.

Do Until objTextStream.AtEndOfStream

' Trim leading and trailing blanks.

strComputer = Trim(objTextStream.ReadLine)
strUser = Trim(objTextStream.ReadLine)


' Skip blank lines.

If (strComputer <> "") Then

' Bind to local Administrators group on remote computer.
' bind to domain user

' Trap error if computer does not exist or is off line.

On Error Resume Next
Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators,group")
Set objUser = GetObject("WinNT://" & strDomain & "/" & strUser & ",user")

If (Err.Number <> 0) Then
On Error GoTo 0
Wscript.Echo "Fail to bind to group on " & strComputer
Else
On Error GoTo 0
' Check if user is already a member.
If (objGroup.IsMember(objUser.AdsPath) = False) Then
' Add the domain user to the local group.
objGroup.Add(objUser.ADsPath)
End If
End If
End If
Loop


.



Relevant Pages

  • Re: script to add multple users to local admin group on servers
    ... ' Script to add domain user to local administrators group ... Dim strUser, objUser, objGroup, objFSO, objTextStream ... Set objTextStream = objFSO.OpenTextFile ... On Error GoTo 0 ...
    (microsoft.public.windows.server.scripting)
  • need help with OpenDSObject
    ... I am writing an HTA that will allow me to add a domain user to the ... local Administrators group and can be run even as a lowly user provided ... Sub Promote ... Set objGroup = objDSO.OpenDSObject ...
    (microsoft.public.scripting.vbscript)
  • Re: Question about group
    ... It would mean that domain user can log on to any computer and get admin rights to ... adding the built-in role "INTERACTIVE" to the local Administrators group. ...
    (microsoft.public.win2000.security)
  • RE: Remove domain user from local administrators group
    ... > domain user is assigned to local administrators group. ... Regards ...
    (Focus-Microsoft)
  • RE: Add AD user to localgroup
    ... if your script runs locally on a Win2k or WinXP workstation, you can use the following code (please note that you can still use the ADSI WinNT: provider to access objects in an Active Directory domain): ... ' bind to the local Administrators group ... add the domain user to the local group ...
    (microsoft.public.scripting.vbscript)

Loading