111 lines
2.8 KiB
Batchfile
111 lines
2.8 KiB
Batchfile
|
@echo off
|
|||
|
REM Attention encodage OEM-850
|
|||
|
|
|||
|
setlocal enableextensions enabledelayedexpansion
|
|||
|
|
|||
|
:checkadmin
|
|||
|
REM Check ex<65>cution du script en tant qu'admin
|
|||
|
net session > NUL 2>&1
|
|||
|
if %errorlevel% EQU 0 goto start
|
|||
|
echo LE SCRIPT N'EST PAS LANC<4E> EN TANT QU'ADMINISTRATEUR !
|
|||
|
pause > nul
|
|||
|
exit
|
|||
|
|
|||
|
:start
|
|||
|
REM Check si la liste d'users existe
|
|||
|
cls
|
|||
|
if not exist %~dp0\users_to_create.txt (
|
|||
|
echo Le fichier users_to_create.txt n'existe pas.
|
|||
|
echo Veuillez le cr<63>er, avec un utilisateur par ligne sous cette forme :
|
|||
|
echo prenom.nom;Pr<50>nom NOM
|
|||
|
echo.
|
|||
|
echo ATTENTION le fichier doit <20>tre encod<6F> en OEM-850
|
|||
|
pause > nul
|
|||
|
exit
|
|||
|
)
|
|||
|
|
|||
|
rem Comptage du nombre de lignes, et donc d'users
|
|||
|
set /a lines=0
|
|||
|
for /f "delims=;" %%L in ('type %~dp0\users_to_create.txt') do (set /a lines+=1)
|
|||
|
|
|||
|
REM Pour chaque ligne, cr<63>er un user avec son username, et son fullname
|
|||
|
REM incr<63>mentation du compteur pour donner une progression
|
|||
|
REM d<>finition des quotas
|
|||
|
REM /!\ Le mod<6F>le demand<6E> par la commande doit exister au pr<70>alable /!\
|
|||
|
set /a count=0
|
|||
|
for /F "delims=; tokens=1,2" %%A in ('type %~dp0\users_to_create.txt') do (
|
|||
|
set user=%%A
|
|||
|
set fname=%%B
|
|||
|
set user=!user:~0,20!
|
|||
|
call :create >> %~dp0\new_users.log
|
|||
|
set /a count+=1
|
|||
|
cls
|
|||
|
if !count! EQU 1 echo !count!/%lines% utilisateur cr<63><72>.
|
|||
|
if !count! GTR 1 echo !count!/%lines% utilisateurs cr<63><72>s.
|
|||
|
)
|
|||
|
|
|||
|
REM Fin du script
|
|||
|
title Cr<43>ation des utilisateurs termin<69>e.
|
|||
|
pause > nul
|
|||
|
exit
|
|||
|
|
|||
|
:create
|
|||
|
title Cr<43>ation de l'utilisateur %user% - %fname%
|
|||
|
|
|||
|
REM check existence user, si oui, v<>rifier existence dossier perso
|
|||
|
set exists=0
|
|||
|
net user !user! > NUL 2>&1
|
|||
|
if %errorlevel% EQU 0 (
|
|||
|
set exists=1
|
|||
|
goto perso
|
|||
|
)
|
|||
|
|
|||
|
call :pass
|
|||
|
net user !user! !password! /add /DOMAIN /FULLNAME:"!fname!"
|
|||
|
|
|||
|
|
|||
|
:perso
|
|||
|
REM check si dossier perso existe, si oui d<>finir quota
|
|||
|
if exist %~dp0\Perso\!user! goto quota
|
|||
|
echo Cr<43>ation du dossier ...
|
|||
|
mkdir %~dp0\Perso\!user!
|
|||
|
echo.
|
|||
|
|
|||
|
echo D<>finition du propri<72>taire ...
|
|||
|
icacls %~dp0\Perso\!user! /setowner !user! /T
|
|||
|
echo.
|
|||
|
|
|||
|
echo D<>sactivation de l'h<>ritage ...
|
|||
|
icacls %~dp0\Perso\!user! /inheritance:d
|
|||
|
echo.
|
|||
|
|
|||
|
echo Modification des droits ...
|
|||
|
icacls %~dp0\Perso\!user! /grant !user!:(OI)(CI)(NP)(F)
|
|||
|
icacls %~dp0\Perso\!user! /grant "Administrateurs":(OI)(CI)(F)
|
|||
|
icacls %~dp0\Perso\!user! /remove "Tout le monde"
|
|||
|
icacls %~dp0\Perso\!user! /remove "Utilisateurs authentifi<66>s"
|
|||
|
echo.
|
|||
|
|
|||
|
:quota
|
|||
|
echo D<>finition du quota...
|
|||
|
dirquota quota add /Path:E:\Perso\!user! /SourceTemplate:"Perso 10 Go"
|
|||
|
if %exists% EQU 1 goto :EOF
|
|||
|
|
|||
|
echo !user! !password!>>%~dp0\users_created.txt
|
|||
|
goto :EOF
|
|||
|
|
|||
|
|
|||
|
:pass
|
|||
|
REM set /P _length=Password Length: %==%
|
|||
|
set _length=8
|
|||
|
set /a z = %_length%
|
|||
|
set "string=ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz123456789"
|
|||
|
set "password="
|
|||
|
for /L %%i in (1,1,!z!) do call :_genRand
|
|||
|
REM echo Password is: %password%
|
|||
|
goto :EOF
|
|||
|
|
|||
|
:_genRand
|
|||
|
set /a x=%random% %% 62
|
|||
|
set password=%password%!string:~%x%,1!
|
|||
|
goto :eof
|