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
Bookmarks