Задача: добавить доменную группу в LocalAdministrators группу на каждом сервере из списка в файле servers.txt (один сервер на строку)
Запускать лучше с помощью cscript что бы не щелкать ОК на каждое сообшение.
Вот слепил из того что было
Код:
'Add2LocalAdmin.vbs
Dim objFSO, strTextFile, strData, strLine, arrLines, Domain, GroupName, ComputerName
CONST ForReading = 1
Domain = "Pre2000domainname"
GroupName = "GROUP-YOU-NEED-TO-ADD"
'name of the text file with list of servers
strTextFile = "servers.txt"
'Create a File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Open the text file - strData now contains the whole file
strData = objFSO.OpenTextFile(strTextFile,ForReading).ReadAll
'Split the text file into lines
arrLines = Split(strData,vbCrLf)
'Step through the lines
For Each strLine in arrLines
'wscript.echo strLine
ComputerName = strLine
'aAdd the group to the local administrators group
Wscript.echo vbCrLf & "Adding " & Domain & "\" & GroupName & _
" to the local administrators group on " & ComputerName
Select Case AddGroupToLocalAdmins(ComputerName,Domain,GroupName)
Case 0
wscript.echo " Succes"
Case 1
wscript.echo " Failed - unable to add the account to the local administrators group"
Case 2
wscript.echo " Already a member"
Case 3
wscript.echo " Failed - Unable to connect to the computer"
End Select
Next
'Cleanup
Set objFSO = Nothing
'#############################
'Function AddGroupToLocalAdmins
'Variables
'ComputerName
'Domain of Group being added
'GroupName (User account can be used as well)
'Returns
'0 if Group is added successfully to the local Admin group
'1 if function was unable to add the Group to the local Admin group
'2 if Group is already a member of the local Admin group
'3 if the function was unable to connect to the specified Computer
Function AddGroupToLocalAdmins(ComputerName,Domain,GroupName)
On Error Resume Next
'Create an group object referencing the local Administrators group on the
'Computer
Set objLocalGroup = GetObject("WinNT://" & ComputerName & "/Administrators, group")
If Err.Number = 0 Then
'Check to see if the Group already exists in the local Admin group
For each Group in objLocalGroup.Members
If Instr(ucase(Group.ADSPath),ucase(Domain & "/" & GroupName)) <> 0 Then
AlreadyExists = True
End If
Next
'Add the specified group to the local Administrators group if it doesn't already
'exist
If AlreadyExists = False Then
objLocalGroup.Add("WinNT://" & Domain & "/" & GroupName)
If Err.Number = 0 Then
AddGroupToLocalAdmins = 0
Else
AddGroupToLocalAdmins = 1
Err.Clear
End If
Else
AddGroupToLocalAdmins = 2
End If
Else
AddGroupToLocalAdmins =3
Err.Clear
End If
End Function
'#############################