Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding Users to Local Admin Group

Status
Not open for further replies.

kachbo1

IS-IT--Management
Nov 16, 2004
40
GB
Hi,

I have a script which works preety well when run manually. I would like to automate the process and run this via GPO.

The script basically reads a txt file (which has a list of PC Names)and adds a user to the local admin group on the PC's incuded in the txt file.

I would like to add the username in the script and also give rights (see below) rather then inserting the value in the pop up box. The script asks you the username and the asks weather to add or remove rights.





Set oWshNet = CreateObject("WScript.Network")
Set oFSO = CreateObject("Scripting.FileSystemObject")
set WSHShell = wscript.createObject("wscript.shell")

sUser = InputBox("Enter user name on network")
If sUser = "" Then
WScript.Echo "No user input, aborted"
WScript.Quit
End If

tmp = InputBox("Enter 1 to Give rights or 2 to Remove rights")
If tmp = "" Then
WScript.Echo "No user input, aborted"
WScript.Quit
End If

If tmp=1 then
'open the data file
Set oTextStream = oFSO.OpenTextFile("wslist.txt")

'make an array from the data file
RemotePC = Split(oTextStream.ReadAll, vbNewLine)

'close the data file
oTextStream.Close

For Each strComputer In RemotePC

sNetBIOSDomain = oWshNet.UserDomain

Set oGroup = GetObject("WinNT://" & strComputer & "/Administrators,group")
Set oUser = GetObject("WinNT://" & sNetBIOSDomain & "/" & sUser & ",user")

' suppress errors in case the user is already a member
On Error Resume Next

oGroup.Add(oUser.ADsPath)

Next

wscript.echo "Rights Given"

else

'open the data file
Set oTextStream = oFSO.OpenTextFile("wslist.txt")

'make an array from the data file
RemotePC = Split(oTextStream.ReadAll, vbNewLine)

'close the data file
oTextStream.Close

For Each strComputer In RemotePC

sNetBIOSDomain = oWshNet.UserDomain

Set oGroup = GetObject("WinNT://" & strComputer & "/Administrators,group")
Set oUser = GetObject("WinNT://" & sNetBIOSDomain & "/" & sUser & ",user")

' suppress errors in case the user is already a member
On Error Resume Next


oGroup.Remove(oUser.ADsPath)

Next

wscript.echo "Rights Taken away"

End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top