# Adduser Script


# USAGE:
# Adduser userid RealName Comment Dept
# values with spaces must be in quotes
#   eg adduser atu99999 "Test-User, Arthur" "Dummy user name for testing" Technology

# Get User Details
use Win32API::Net;
use Win32::NetAdmin;
use Win32::AdminMisc;

if ( @ARGV ne 4 ) die ("Wrong Number of Args");

($UserId,$UserRealName,$UserComment,$UserDept)=$ARGV;

IF "%UserId" == "" GOTO USAGE
IF "%UserRealName" == "" GOTO USAGE
IF "%UserComment" == "" GOTO USAGE
IF "%UserDept" == "" GOTO USAGE

# $Defaults
$HomeFilesServer="ukcr07";
$HomefilesArea="\\$HomeFilesServer\Home_Files$";
$ProfilesArea="\\UKCR05\Profiles$\$UserId";
$DomainName="NTDOMAIN";
$Password="newuser";
Win32::NetAdmin::GetDomainController($HomeFilesServer, $DomainName, $DomainCtlr);

# Create New User

Win32API::Net::UserAdd($DomainCtlr, $UserId, $Password, passwordAge, privilege, homeDir, $UserComment, flags, $UserId.bat)

#NET USER $UserId newuser /ADD /DOMAIN /COMMENT:%UserComment% /FULLNAME:%UserRealName% /SCRIPTPATH:$UserId.bat /PROFILEPATH:"\\ukcr05\DFSROOT\profiles\$UserId"
# pause
# Create Home directory

mkdir $HomeFilesArea\$UserId
mkdir $HomeFilesArea\$UserId\email
mkdir $HomeFilesArea\$UserId\wwdata
mkdir $HomeFilesArea\$UserId\xldata
mkdir $HomeFilesArea\$UserId\powerpnt

# pause
# $Access

cacls $HomeFilesArea\$UserId /t /g %DomainName%\$UserId:f system:f "%DomainName%\domain admins":f /c
# pause
# Create as share

rmtshare \\%HomeFilesServer%\$UserId$=e:\home_FILES\$UserId /grant %DomainName%\$UserId:f /grant system:f /grant "%DomainName%\domain admins":f /ark %UserRealName%
# pause
# Add to DFS

c:\WINNT\system32\Dfs\DFSCMD /MAP "\\UKCR05\DFSROOT\HOME_FILES\$UserId" \\%HomeFilesServer%\$UserId$
# pause


# Create Profile

mkdir %ProfilesArea%
# $Access

cacls %ProfilesArea% /t /g %DomainName%\$UserId:f system:f "%DomainName%\domain admins":f /c
# pause

# Add to DFS

c:\WINNT\system32\Dfs\DFSCMD /MAP "\\UKCR05\DFSROOT\PROFILES\$UserId" %ProfilesArea%
# pause



# Create startup script

sed -e "s/(userid)/$UserId/g" -e "s/(department)/%UserDept%/g"  \\ukcr00\Master_scripts$\master.bat > \\ukcr00\Master_scripts$\$UserId.bat


GOTO END

:USAGE

echo
echo USAGE:
echo
echo Adduser userid RealName Comment Dept
echo
echo values with spaces must be in quotes
echo
echo   eg adduser atu99999 "Test-User, Arthur" "Dummy user name for testing" Technology

:END

