Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off
- setlocal
- SETLOCAL ENABLEDELAYEDEXPANSION
- :: Jättefult work around för tomma delims
- :: http://stackoverflow.com/questions/17556976/batch-script-skipping-blank-entries-in-a-csv-when-delim-is
- setlocal EnableDelayedExpansion
- set count=1
- FOR /F "delims=" %%L in (UserData.csv) DO (
- set "line=%%L;;;;;;;;"
- set "line=#!line:;=;#!"
- FOR /F "tokens=1-12 delims=;" %%a in ("!line!") DO (
- set "param1=%%a"
- set "param2=%%b"
- set "param3=%%c"
- set "param4=%%d"
- set "param5=%%e"
- set "param6=%%f"
- set "param7=%%g"
- set "param8=%%h"
- set "param9=%%i"
- set "param10=%%j"
- set "param11=%%k"
- set "param12=%%l"
- set "param1=!param1:~1!"
- set "param2=!param2:~1!"
- set "param3=!param3:~1!"
- set "param4=!param4:~1!"
- set "param5=!param5:~1!"
- set "param6=!param6:~1!"
- set "param7=!param7:~1!"
- set "param8=!param8:~1!"
- set "param9=!param9:~1!"
- set "param10=!param10:~1!"
- set "param11=!param11:~1!"
- set "param12=!param12:~1!"
- echo !param1! !param2! !param5!
- echo %%a %%b %%e
- set departmentShort=!param5:~0,1!!param5:~-1!
- CALL :LoCase departmentShort
- echo !departmentShort!
- set nameShort=!param1:~0,1!!param3:~0,1!
- CALL :LoCase nameShort
- echo !nameShort!
- :: user
- set result=""
- call :getUserNum !nameShort! 111 !departmentShort! result
- set result=!nameShort!!result!!departmentShort!
- echo !result!
- :: Skapa användaren
- REM dsadd user cn=MikeDan,cn=users,dc=company,dc=test -fn <FistName> -mi <Initial> -display <DisplayName -pwd <Password> -memberof <Group> -tel
- <PhoneNumber> -email <Email> -title <Title> -dept <Department> -samid <samid> -disabled no
- set /a count=!count!+1
- )
- )
- goto:eof
- :getUserNum
- dsquery user OU=Users,OU=Kalmar,OU=CompanyTest,DC=company,DC=test -samid %1%2%3|find /v "" >nul
- if errorlevel 1 (
- set %4=%2
- goto:eof
- ) else (
- set /a newNum=%2*2
- set result=""
- call :checkUser %1 !newNum! %3 result
- set %4=!result!
- goto:eof
- )
- :LoCase
- :: Subroutine to convert a variable VALUE to all lower case.
- :: The argument for this subroutine is the variable NAME.
- SET %~1=!%1:A=a!
- SET %~1=!%1:B=b!
- SET %~1=!%1:C=c!
- SET %~1=!%1:D=d!
- SET %~1=!%1:E=e!
- SET %~1=!%1:F=f!
- SET %~1=!%1:G=g!
- SET %~1=!%1:H=h!
- SET %~1=!%1:I=i!
- SET %~1=!%1:J=j!
- SET %~1=!%1:K=k!
- SET %~1=!%1:L=l!
- SET %~1=!%1:M=m!
- SET %~1=!%1:N=n!
- SET %~1=!%1:O=o!
- SET %~1=!%1:P=p!
- SET %~1=!%1:Q=q!
- SET %~1=!%1:R=r!
- SET %~1=!%1:S=s!
- SET %~1=!%1:T=t!
- SET %~1=!%1:U=u!
- SET %~1=!%1:V=v!
- SET %~1=!%1:W=w!
- SET %~1=!%1:X=x!
- SET %~1=!%1:Y=y!
- SET %~1=!%1:Z=z!
- SET %~1=!%1:Å=å!
- SET %~1=!%1:Ä=ä!
- SET %~1=!%1:Ö=ö!
- GOTO:EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement