#114564 - 2004-02-22 10:17 AM
adding a user to all servers ( local user)
|
juanbabi
Fresh Scripter
Registered: 2004-02-09
Posts: 15
|
Hi !! I need to write a script that will run on all the servers in my domain . the script needs to create a local user name test and pass 1234 with admin rights.I looked for an adduser or something close in the manual and didnt find any thing.can some one just tell me the direction ( the initial command that my script will be based upon ?) ,I also search this site and didnt found a clue...
thanks
|
|
Top
|
|
|
|
#114565 - 2004-02-22 02:32 PM
Re: adding a user to all servers ( local user)
|
Co
MM club member
 
Registered: 2000-11-20
Posts: 1342
Loc: NL
|
|
|
Top
|
|
|
|
#114566 - 2004-02-22 04:46 PM
Re: adding a user to all servers ( local user)
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Quote:
Creating Users on Member Servers and Windows 2000 Professional
[This is preliminary documentation and subject to change.]
To create a user on a member server or computer running Windows 2000 Professional
Bind to the computer using the following rules:
Use an account that has sufficient rights to access that computer.
Use the following binding string format using the WinNT provider, computer name, and an extra parameter to tell ADSI that it is binding to a computer:
<a href="WinNT://sComputerName" target="_blank">WinNT://sComputerName</a>, computer
where sComputerName is the name of the computer who groups you want to access.
In the binding string, the ",computer" parameter tells ADSI that it is binding to a computer and allows the WinNT: provider's parser to skip some ambiguity resolution queries to determine what type of object you are binding to.
Bind to the IADsContainer interface.
Specify "user" as the class using IADsContainer::Create to add the user.
Write the user to the computer's security database using IADs::SetInfo.
This code should work but is currently giving me an error on my computer. Maybe I screwed something up... Your mileage may vary...
Code:
break On
$Server = "Bullockha"
$oComputer = GetObject("WinNT://" + $Server + ",computer")
? ConvertCOMerror(@error)
$oUser = $oComputer.Create("user", "MyNewUser")
? ConvertCOMerror(@error)
$oUser.SetPassword("NewPassword")
? ConvertCOMerror(@error)
$oUser.SetInfo
? ConvertCOMerror(@error)
Function ConvertCOMerror($error)
$error = val("&"+Right(DecToHex($error),4))
? "Error: $error"
shell "net helpmsg $error"
Endfunction
[edit]
The problem was that we enforce STRONG passwords via policy and "NewPassword" did not meet those requirements.
$oUser.SetPassword("NewPassword2")
made the program work.
[/edit]
Edited by Howard Bullock (2004-02-22 04:48 PM)
|
|
Top
|
|
|
|
#114572 - 2004-02-23 04:27 AM
Re: adding a user to all servers ( local user)
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11631
Loc: CA
|
Well here is something I came up with which is quite similar to Howards 
But mine also adds the new user to the local Administrators group as well which is what I think you also asked for.
NOTE: - ANDY I would typically agree with you about showing noobies how to circumvent security, but this code does not do that. The person running this script MUST already have local Administrative rights on the system there attempting to add a user to otherwise this script will fail.
Code:
Debug Off Break On Dim $iRC $iRC=SetOption('Explicit','On') $iRC=SetOption('NoVarsInStrings','On') Dim $NewUser $NewUser = CreateUser('NameOfComputer','johndoe','1234')
Function CreateUser($Remote,$Name,$Password) Dim $System,$NewUser,$Group,$User $System = GetObject("WinNT://" + $Remote + ",Computer") $NewUser = $System.Create("User", $Name) $NewUser.SetPassword($Password) $NewUser.SetInfo fnCOMErr(@ERROR) ? 'Account creation: ' +@ERROR +" : " +@SERROR $Group = GetObject("WinNT://" + $Remote + "/Administrators,Group") $User = GetObject("WinNT://" + $Remote + "/"+$Name+",User") $Group.Add($User.ADsPath) fnCOMErr(@ERROR) ? 'Add to Admin Group: ' +@ERROR +" : " +@SERROR EndFunction
Function fnCOMErr($lErr) If $lErr<0 $lErr=VAL("&"+Right(DecToHex($lErr),4)) EndIf Exit $lErr Endfunction
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 302 anonymous users online.
|
|
|