Thought some of you might want to look at this script. Rufff Rufff but might help some of you out. Creates two accounts on different domains for all of our users. Then updates depts via an e-mail. Takes a minute to run. First asks for info on user. Then asks if you want to add more users. After you are done adding users it asks you for a Adminstrator account and password on the Domain controllers to be able to run the scripts. These scripts require an dos e-mail program if you want the e-mail option to work. Also require the Second file useradd.bat to located on the server and require the Su.exe utility located on NT 4 resource Kit to be on the servers as well.Useradd.kix
; ***********************************************************************
; ***********************************************************************
; Script Requirements
;
; E-mail Program on Client running this Program (we use maillistbot a dos e-mail program)
; Useradd.bat on Servers Adding Users
; Su.exe on servers adding Users
; Domain Admin account on Servers
;
;
;
; ***********************************************************************
; ***********************************************************************
; ******************************************************************
; *********************Servers to Update********************************
$server1=**Your server name**
$server2=**Your server name**
; ******************************************************************
; ******************************************************************
; *********************Users to E-mail********************************
; includes Password
$email1=**Administrators e-mail**
; No password
$email2=**HR e-mails**
; ******************************************************************
; ******************************************************************
; *********************Create Useradd Dir********************************
IF EXIST ("\\$SERVER1\C$\NEWUSER\DELNEWUSER.BAT")
GOTO "STEMP2"
ELSE MD "\\$SERVER1\C$\NEWUSER"
Shell "cmd /c echo echo off >> \\$SERVER1\C$\NEWUSER\DELNEWUSER.BAT"
Shell "cmd /c echo call c:\newuser\netsend.bat >> \\$SERVER1\C$\NEWUSER\DELNEWUSER.BAT"
Shell "cmd /c echo del c:\newuser\newuser.bat >> \\$SERVER1\C$\NEWUSER\DELNEWUSER.BAT"
Shell "cmd /c echo del c:\newuser\superbat.bat >> \\$SERVER1\C$\NEWUSER\DELNEWUSER.BAT"
Shell "cmd /c echo del c:\newuser\netsend.bat >> \\$SERVER1\C$\NEWUSER\DELNEWUSER.BAT"
ENDIF
:STEMP2
IF EXIST ("\\$SERVER2\C$\NEWUSER\DELNEWUSER.BAT")
GOTO "START"
ELSE MD "\\$SERVER2\C$\NEWUSER"
Shell "cmd /c echo echo off >> \\$SERVER2\C$\NEWUSER\DELNEWUSER.BAT"
Shell "cmd /c echo call c:\newuser\netsend.bat >> \\$SERVER2\C$\NEWUSER\DELNEWUSER.BAT"
Shell "cmd /c echo del c:\newuser\newuser.bat >> \\$SERVER2\C$\NEWUSER\DELNEWUSER.BAT"
Shell "cmd /c echo del c:\newuser\superbat.bat >> \\$SERVER2\C$\NEWUSER\DELNEWUSER.BAT"
Shell "cmd /c echo del c:\newuser\netsend.bat >> \\$SERVER2\C$\NEWUSER\DELNEWUSER.BAT"
ENDIF
; *****************************************************************
; *********************Get Variables********************************
:Start
break on cls
? "Username: "
gets $usrname
? "Userid: "
gets $usrid
? "User Password: "
gets $password
:Group
? "Group: "
gets $grp
; ***********************************************************************
; *********************Text File to e-mail********************************
Shell "cmd /c echo . >> c:\newuser.txt"
Shell "cmd /c echo UserName:$usrname >> c:\newuser.txt"
Shell "cmd /c echo UserID:$usrid >> c:\newuser.txt"
Shell "cmd /c echo Password:$password >> c:\newuser.txt"
Shell "cmd /c echo Group:$grp >> c:\newuser.txt"
Shell 'cmd /c echo E-mail Address: $usrid@@lexgen.com >> c:\newuser.txt'
; ***********************************************************************
; *********************Text File to Admin********************************
Shell "cmd /c echo . >> c:\newusera.txt"
Shell "cmd /c echo UserName:$usrname >> c:\newusera.txt"
Shell "cmd /c echo UserID:$usrid >> c:\newusera.txt"
Shell "cmd /c echo Group:$grp >> c:\newusera.txt"
Shell 'cmd /c echo E-mail Address: $usrid@@lexgen.com >> c:\newusera.txt'
; ***********************************************************************
; ****************Copy files to Server*******************************************
Shell 'cmd /c echo call useradd $usrid $password "$usrname" $grp >> \\$server1\c$\newuser\newuser.bat'
Shell 'cmd /c echo call useradd $usrid $password "$usrname" $grp >> \\$server2\c$\newuser\newuser.bat'
; ***********************************************************************
; ****************CONTINUE Y/N*******************************************
? "Do you want to continue adding Users?(y/n) "
Gets $SELECTION
If $Selection = y
goto "START"
Endif
; ******************************************************************
; ****************Admin Authentication For adding Users*******************************************
cls
? "Enter Your Domain Admin Account. "
gets $adminname
break on cls
dim $apword1A[25]
$apword1 = "" ;Needed to set the string variable.
$apword2 = "" ;Needed to set the string variable.
Gosub Getapword
Goto "Superbat"
;----------------------------
:Getapword
;----------------------------
$xpos = 0 ;set the starting x position, for display only
$ypos = 0 ;set the starting y position, for display only
;--------------------------------------------------------------
;-----------------don't edit below this line-------------------
;--------------------------------------------------------------
$Index1 = 0
$Index2 = 0
if $apword1 = ""
at($xpos,$ypos) "Enter Admin Password: "
else
at($xpos+1,$ypos) "Recomfirm Password: "
$case1x = 1
$case1 = 0
endif
DO
$Index1 = $Index1 + 1
IF $index1 > 24
cls beep
$case1 = 0
$case1x = 0
goto Getapword
ENDIF
:Enterapword_BackSpace
GET $apword1A[$Index1]
select
case $apword1A[$Index1] = chr(8)
if $index1 = 1
beep
goto Enterapword_BackSpace
else
$index1 = $index1 - 1
$case1 = $case1 - 1
at($xpos+$case1x,$ypos+23+$case1) " "
goto Enterapword_BackSpace
endif
case $apword1A[$Index1] = chr(13)
;do nothing
case 1
at($xpos+$case1x,$ypos+23+$case1)"*"
$case1 = $case1 +1
endselect
UNTIL $apword1A[$Index1] = CHR(13)
$Index1 = $Index1 - 1 ;Needed to get rid of the Carriage Return.
if $index1 = 0
beep
goto Getapword
endif
if $apword1 = ""
DO
$Index2 = $Index2 + 1
$apword1 = $apword1 + $apword1A[$Index2]
UNTIL $Index2 = $Index1
goto Getapword
else
DO
$Index2 = $Index2 + 1
$apword2 = $apword2 + $apword1A[$Index2]
UNTIL $Index2 = $Index1
if $apword1 = $apword2
? $apword = $apword2
$apword1 = ""
$apword2 = ""
return
else
at($xpos+$case1x+1,$ypos)"Admin Password's don't match!!!"
Beep Beep
sleep 2
cls
$apword1 = ""
$apword2 = ""
$case1 = 0
$case1x = 0
goto Getapword
endif
return
endif
$apword = $apword1
:Superbat
; ******************************************************************
; *********************Create Superbat.bat********************************
$res=redirectoutput("\\$server1\c$\newuser\superbat.bat",0) "echo $apword| su $adminname c:\newuser\newuser.bat Lexicon"
$res=redirectoutput("\\$server2\c$\newuser\superbat.bat",0) "echo $apword| su $adminname c:\newuser\newuser.bat Lexicon"
; ******************************************************************
; *********************Email Files to Users********************************
SHELL "CMD /C ECHO c:\e-mail\maillistbot -to $email1@@lexgen.com -from SYSTEMSADMIN@@lexgen.com -subject NEWUSERS -server mail.lexgen.com -bodyfile c:\newuser.txt >> c:\newusr.bat"
SHELL "CMD /C ECHO c:\e-mail\maillistbot -to $email2@@lexgen.com -from SYSTEMSADMIN@@lexgen.com -subject NEWUSERS -server mail.lexgen.com -bodyfile c:\newusera.txt >> c:\newusr.bat"
Shell "cmd /c c:\newusr.bat"
; ******************************************************************
; *********************Create netsend.bat********************************
SHELL "CMD /C ECHO NET SEND $adminname Users added to $server1 Update UserManager > \\$server1\c$\newuser\netsend.bat"
SHELL "CMD /C ECHO NET SEND $adminname Users added to $server2 Update UserManager > \\$server2\c$\newuser\netsend.bat"
; ******************************************************************
; *********************Gets current Time and adds 2 minutes ***************
$h = SUBSTR(@time,1,2)
$m = VAL(SUBSTR(@time,4,2))
SELECT
CASE $m = 58
$h = VAL($h) + 1
IF $h = 24 $time = "00:00" ELSE $time = "$h:00" ENDIF
CASE $m = 59
$h = VAL($h) + 1
IF $h = 24 $time = "00:01" ELSE $time = "$h:01" ENDIF
CASE 1
$m = $m + 2
IF $m < 10 $m = "0" + $m ENDIF
$time = $h + ":" + $m
ENDSELECT
; ************************************************************************
; *********************Gets current TIme and adds 3 minutes ***************
$h = SUBSTR(@timea,1,2)
$m = VAL(SUBSTR(@timea,4,2))
SELECT
CASE $m = 58
$h = VAL($h) + 1
IF $h = 24 $timea = "00:00" ELSE $timea = "$h:00" ENDIF
CASE $m = 59
$h = VAL($h) + 1
IF $h = 24 $timea = "00:01" ELSE $timea = "$h:01" ENDIF
CASE 1
$m = $m + 3
IF $m < 10 $m = "0" + $m ENDIF
$timea = $h + ":" + $m
ENDSELECT
; ************************************************************************
; *********************Gets current TIme and adds 4 minutes ***************
$h = SUBSTR(@timeb,1,2)
$m = VAL(SUBSTR(@timeb,4,2))
SELECT
CASE $m = 58
$h = VAL($h) + 1
IF $h = 24 $timeb = "00:00" ELSE $timeb = "$h:00" ENDIF
CASE $m = 59
$h = VAL($h) + 1
IF $h = 24 $timeb = "00:01" ELSE $timeb = "$h:01" ENDIF
CASE 1
$m = $m + 4
IF $m < 10 $m = "0" + $m ENDIF
$timeb = $h + ":" + $m
ENDSELECT
; ************************************************************************
; *********************Run Remote AT Cmd********************************
Shell "cmd /c at \\$server1 $Time c:\newuser\Superbat.bat"
Shell "cmd /c at \\$server2 $Timea c:\newuser\Superbat.bat"
Shell "cmd /c at \\$server1 $Timeb c:\newuser\delnewuser.bat"
Shell "cmd /c at \\$server2 $Timeb c:\newuser\delnewuser.bat"
; ******************************************************************
; *********************Delete Local Files********************************
Del c:\newuser.txt
Del c:\Newusera.txt
Del c:\newusr.bat
Useradd.bat
@Echo off
if "%1"=="" goto helps
echo %3
Set Server=**your server**
echo 1
net user %1 %2 /add /fullname:%3 /homedir:\\%server%\%1$ /scriptpath:logon.bat /profilepath: /expire:never /domain
if not errorlevel 1 echo "User Added"
REM **************'add the user'*********************************
echo 2
REM net localgroup %lgroup% %name% /add
REM if not errorlevel 1 echo "User Added to Local Group"
REM **************'repeat for local groups'**********************
echo 3
net group %4 %1 /add /domain
if not errorlevel 1 echo "User Added to Global Group"
REM **************'repeat for global groups'*********************
echo 4
net group "pass sync" %1 /add /domain
if not errorlevel 1 echo "User Added to Global Group"
REM **************'repeat for global groups'*********************
echo 5
net group "Workstation Admin" %1 /add /domain
if not errorlevel 1 echo "User Added to Global Group"
REM **************'repeat for global groups'*********************
md \\%server%\ufs\%4\users\%1
if not errorlevel=1 echo "User Directory Made"
REM **************'create the user an area'**********************
echo 6
choice /c:YN Do you want to "Copy Default Profile?"
IF ERRORLEVEL 1 xcopy \\%server%\profiles$\template \\%server%\ufs\%4\users\%1\ /e
xcopy \\%server%\ufs\shared\template\default\*.* /s \\%server%\ufs\%4\users\%1
REM if not errorlevel=1 echo "User Template Copied"
REM rem **************copy over a template directory structure'******
echo 7
cacls \\%server%\ufs\%4\users\%1 /e /r Everyone /t
rem **************'remove the everyone permission from directory'
echo 8
echo y| cacls \\%server%\ufs\%4\users\%1 /g %1:F /t
if not errorlevel=1 echo "User full rights Added"
rem ***************gives the user full control'******************
echo 9
cacls \\%server%\ufs\%4\users\%1 /g "lexicon\Domain Admins":F /e /t
echo.
if not errorlevel=1 echo "Domain Admins added to Permisions"
rem **************gives Administrators full control'*************
echo 10
cacls \\%server%\ufs\%4\users\%1 /g termserv\%1:F /e /t
echo 11
cacls \\%server%\ufs\%4\users\%1 /g termserv\fileadmin:F /e /t
echo.
if not errorlevel=1 echo "Domain Admins added to Permisions"
rem **************gives Administrators full control'*************
echo 12
ECHO.
ECHO.
if errorlevel=1 echo ".....***********USER NOT IN TERMSERV DOMAIN************........"
ECHO.
ECHO.
rem **************gives Terminal user full control'*************
echo 13
rem cacls \\%server%\ufs\%4\users\%1 /e /r %4 /t
rem **************'REmove the Group permission from directory'
echo 14
rem cacls \\%server%\ufs\%4\users\%1 /e /r Bioinfo /t
rem **************'REmove the Group permission from directory'
echo 15
set hmshr=%1$
net share %1$=f:\%4\users\%1 /y
goto end
****************************HELP FILE******************************
:helps
@Echo Off
Echo Correct Execution
Echo "useradd <login> <password> <Username> <Group>"
Echo Examples:
echo "useradd jdoe lost "John Doe" biotech"
echo "useradd Bruth baseball "Babe Ruth" sports"
:end