Saturday, May 8, 2010

Scripts - Creating Users, Home Directories, Shares

This batch file is one that I created many years ago, but still use.  It is a simple non-complicated way to automatically create users, apply a password, create their home directory and home share.  Your list of users have to be one to a line in the referenced u:\user.txt  file.  There are many different ways you can script something like this.  I use this on contracts where they don't have someone that can support a script but could a simple batch file.

rem    NB: user home directory is set at Z:\
rem    Use: Users.bat, LogonName, LastName, FirstName   
rem       
net use u: /delete
Net use u: \\ServerName\ShareName
u:
PAUSE
REM for /f %%v in (u:\user.txt) do net user %%v P@ssword /add /fullname:%%v

for /f "eol=; tokens=1,2,3,4 delims=," %%v in (u:\user.txt) do net user %%v P@ssword /add /fullname:"%%w"
PAUSE
for /f "eol=; tokens=1,2,3,4 delims=," %%v in (u:\user.txt) do net user %%v /Comment:"enter comment here" /scriptpath:LogonScript1.bat
PAUSE
REM for /f %%v in (u:\user.txt) do net user %%v /Comment:"enter comment here" /scriptpath:LoginScript1.bat
for /f %%v in (u:\user.txt) do net group "Domain Users" %%v /add
for /f %%v in (u:\user.txt) do net group GlobalGroupName %%v /add
for /f %%v in (u:\user.txt) do net group GlobalGroupName %%v /add

PAUSE

::creates directory for each user
u:
for /f %%v in (u:\user.txt) do md u:\%%v

::Gives the user ownership to his directory
for /f %%v in (u:\user.txt) do subinacl /subdirectory u:\%%v /setowner=%%v /grant=%%v=F

::Creates a remote hidden share and Gives Change permissions to the user

for /f %%v in (u:\User.txt) do net share %%v=d:\users\SubDirectory\%%v /grant:%%v,CHANGE

REM if you need to delete shares perform the following command
REM for /f %%v in (u:\user.txt) do net share \\ServerName\%%v /DELETE

PAUSE

Published: 8/10/2005 9:03 PM

No comments:

Post a Comment