Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
i am trying to make a vbs add users to the local administrator group from a list of computers stored on a text file. here is what i have so far:
option explicit
const COMP_FILE = "computers.txt"
const FOR_READING = 1dim fso, ts, strMac, strCommand
set wshShell = createObject("WScript.shell")
set fso = createObject("scripting.filesystemobject")
set ts = fso.opentextfile(COMP_FILE, FOR_READING)
do until ts.atendofstream
strMac = ts.readline
strComputer = addColons(strMac)function addColons(str)
dim i, temptemp = mid(str, 1, 2)
for i = 3 to 11 step 2
temp = temp & ":" & mid(str, i, 2)
next
addColons = temp
end function
'
LoopSet objGroup = GetObject("WinNT://" & strComputer & "/Administrators")
Set objUser = GetObject("WinNT://domain/user")
objGroup.Add(objUser.ADsPath)i got these from examples and dont know all that much of vbs language.
any help would be appreciatedMathew

Wait, what are you asking for? Do you need to make this account on the PC list and assign it to the administrator group? Does the user already exist? Why are you adding colons?

lol as i said, i dont know that much of vbs.
i wrote the bottom bit after loop, and i got the reading from text file from another script.
the idea is to get the vbs to read a text file, which has all the names of the computers in that text file.
then go to those computers, add a domain member to the local administrators group.i dont know what colons are.
i just realised the topic of this is "local users to computers" my bad, its adding domain users to local administrators group.

All right, I'm still not sure if you want to create a new user and assign him to the local Administrators, or if you want to do it with an NT4 domain user, or an Active Directory user. I'm going to assume the later.
I haven't tried to see if this works, but the AD part comes from Microsoft's script repository, and the rest of it comes from a script I used in the past (which was also biased off of the script repository).
This board's word wrapping is a pain; I'm still not sure if it'll wrap lines and break code.
Usage: Save this script as whatever.vbs, then drag and drop your file of computer names on the script.
Script assumes one line = one computer.
You'll need to replace the LDAP line with the user in question.
Code Begins:Option Explicit
Dim sOutput
Dim oUser, oGroupsOutput = "Results:" & vbNewLine
Set oUser = _
GetObject("LDAP://cn=Razor23,OU=is,dc=really,dc=great,dc=com")With _
CreateObject("Scripting.FileSystemObject").OpenTextFile(WScript.Arguments(0))
On Error Resume Next
Do Until .AtEndOfStream
Set oGroup = GetObject("WinNT://" & Trim(.ReadLine) _
& "/Administrators,group")
oGroup.Add(oUser.ADsPath)If Err.Number = 0 Then
sOutput = sOutput & sComputer & " DONE" & vbNewLine
Else
sOutput = sOutput & sComputer & " ERROR" & vbNewLine
Err.Clear
End If
Loop
End With
WScript.Echo sOutput

that script look good! makes my script look like it was made from a 4 year old... thanks!
i have figured out another way of doing it, instead of getting the computer names from a text file:
Dim strComputer1, strComputer2, objGroup, objUser, objGroup1, objUser1
strComputer1 = "netbiosnameExample"
strComputer2 = "ComputerNameExample"Set objGroup = GetObject("WinNT://" & strComputer1 & "/Administrators")
Set objUser = GetObject("WinNT://domainexample/user")
objGroup.Add(objUser.ADsPath)Set objGroup1 = GetObject("WinNT://" & strComputer2 & "/Administrators")
Set objUser1 = GetObject("WinNT://domainExample/user")
objGroup1.Add(objUser.ADsPath)but there are about 20 computers that need a ADUC network structure user account, or domain user added to the local administrators to each computer.
thanks again ill try it out and let you know!

omg this script is da best!!!!
it works like a charmed!
i wasnt sure about the line:
GetObject("LDAP://cn=Razor23,OU=is,dc=really,dc=great,dc=com")so i changed it to:
GetObject("WinNT://domainExample/UserExample")thanks again!

![]() |
renaming with dos?
|
Script for XP
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |