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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

script to add users to groups.

Status
Not open for further replies.

parker309

MIS
Jul 27, 2000
214
US
Below is the script I am using to try and add a domain user to the local administrator group on about fifty workstations. Unfortunately since the local user is the only one in the local admin group I do not "technically" have permission to add a domain user. This script works when run locally but I want to run it in a loop to all fifty machines over the network. Is there a way to embed a username and password into the script? Thanks.


'this is domain group name in general, adminstrators in particular
sdomgrp= Chr(34)& "cuzone\local admin machine" & Chr(34) '<<<input domain group name
sdomgrp= """cuzone\local admin users"""

'these 2 variables varying host to host
slocgrp="administrators" '<<<input local group name
slochost="mis133" '<<<input local machine name

scmd="net localgroup " & slocgrp & " " & sdomgrp & " /add"

set svcproc=getobject("winmgmts:\\" & slochost & "\root\cimv2:win32_process")
iret=svcproc.create(scmd,nul,nul,pid)
if iret=0 then
wscript.echo "net localgroup successfully launched on " & slochost
else
wscript.echo "net localgroup failed to launched on " & slochost
end if
set svcproc=nothing

 
Hello parker309,

To bind to the remote using alternative credential, you have to make a detour using swbemlocator then connectserver.
[tt]
suser="cuzone\jsmith"
spwd="xxxxxxxx"
slochost="mis133"

set oloc=createobject("wbemscripting.swbemlocator")
set svc=oloc.connectserver(slochost,"root\cimv2",suser,spwd)
set svcproc=svc.get("win32_process")
[/tt]
There may be more parameters you want to set, check the documentation on the swbemlocator. Those parameters shown above are just for illustration, you have to make them good.

regards - tsuji
ps. The code you listed, nul is a typo for null. But, it doesn't that matter.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top