我已经尝试了一些东西,但我似乎无法获取我的.bat文件以提供正确的输出并读取输入的第一行。任何帮助将不胜感激。我正在尝试在Active Directory中创建大规模帐户。
@echo off
echo ---- >C:\NewUserCreation\createdusers.txt
setlocal
FOR /F "eol=; tokens=1-12* delims=~" %%i in (C:\NewUserCreation\newusers.txt) do (
set "_lastname=%%i"
set "_firsname=%%j"
set _QWERTY=%%k
call set _midinit=%%_QWERTY:~0,2%%
set _edipi=%%l
set _ptc=%%m
set _ranktitle=%%n
set _subcomponent=%%o
set _unit=%%p
set _position=%%q
set _email=%%r
set _descr=%%s
call :do_user
)
endlocal
notepad C:\NewUserCreation\createdusers.txt
goto :EOF
:do_user
if "%_midinit%"=="%_edipi%" goto :no_middlename
set _samacctname1=%_firsname%.%_midinit%.%_lastname%
set _userPrincipalName=%_edipi%
call :find_existing_user
call set _samacctname=%_samaccountname%
call set _lastinit=%%_lastname:~0,1%%
C:\NewUserCreation\admod -h mydomaincontroller -add -b "cn=%_lastname%\, %_firsname% %_midinit%,ou=NewUsers,ou=n,ou=n,dc=n,dc=n,dc=n,dc=n" objectclass::user "sn::%_lastname%" "givenname::%_firsname%" "initials::%_midinit%" "personaltitle::%_ranktitle%" "company::%_subcomponent%" "department::%_unit%" "PhysicalDeliveryOfficeName::%_position%" "title::%_position%" "employeetype::%_ptc%" "displayname::%_descr%" "description::%_descr%" "samaccountname::%_samacctname%" "st::Anywhere,US" "streetAddress::%_unit%" "postalCode::36805" "countryCode::111" "c::USA" "co::United States" "l::Corporation" "telephoneNumber::DSN 318-872-XXXX" "userPrincipalName::%_edipi%@domain" "userPassword::password"
if /I %ERRORLEVEL% EQU 0 (
set _resultcode=Success
if /I %_samnametest% EQU 274 (call set _resultcode=%%_resultcode%%-DUP)
) ELSE set _resultcode=-ERROR-
@echo on
sleep 15
net user %_samacctname% /DOMAIN /passwordreq:yes
C:\Windows\System32\dsquery * "ou=n,ou=n,dc=n,dc=n,dc=n,dc=n" -filter "(&(objectclass=user)(samaccountname=%_samacctname%))" -s mydomain |exchmbx -me SMTP:%_email%"
@echo off
echo %_resultcode%. . . %_samacctname% Contact: SMTP:%_email% >>C:\NewUserCreation\createdusers.txt
goto :EOF
:find_existing_userz
set _search4Name=%_samacctnamez%
call set _samNameSearchz=%%_search4Name:~0,20%%
call set _samNameSearchzv=%%_search4Name:~0,16%%274
C:\Windows\System32\dsquery * "ou=n,ou=n,dc=n,dc=n,dc=n,dc=n" -filter "(&(&(samaccountname=%_search4Name%)(ObjectClass=User))(!objectClass=computer))" -attr samaccountname|find /I "%_samNameSearchz%" >"%_samNameSearchz%.tmp"
call :samnamefilesizez %_samNameSearchz%.tmp _samNameSearchsizez
del %_samNameSearchz%.tmp
if /I %_samNameSearchsizez% LEQ 1 (set _samaccountnamez=%_samNameSearchz%) ELSE (
set _samaccountnamez=%_samNameSearchzv%
set _lastnamez=%_lastnamez%274
)
echo resulting_sam_account_name %_samaccountnamez%
call set _samnametestz=%_samaccountnamez:~-3%
goto :EOF
:find_existing_user
set _search4Name=%_samacctname1%
call set _samNameSearch=%%_search4Name:~0,20%%
call set _samNameSearchv=%%_search4Name:~0,16%%274
C:\Windows\System32\dsquery * "ou=n,ou=n,dc=n,dc=n,dc=n,dc=n" -filter "(&(&(samaccountname=%_samNameSearch%)(ObjectClass=User))(!objectClass=computer))" -attr samaccountname|find /I "%_samNameSearch%" >%_samNameSearch%.tmp
call :samnamefilesize %_samNameSearch%.tmp _samNameSearchsize
del %_samNameSearch%.tmp
if /I %_samNameSearchsize% LEQ 1 (set _samaccountname=%_samNameSearch%) ELSE (
set _samaccountname=%_samNameSearchv%
set _lastname=%_lastname%274
)
echo resulting_sam_account_name %_samaccountname%
call set _samnametest=%_samaccountname:~-3%
goto :EOF
:samnamefilesize
set %2=%~z1
goto :EOF
:samnamefilesizez
set %2=%~z1
goto :EOF
pause
答案 0 :(得分:0)
我建议您致电 ing:do_user,这是去 到:no_middlename。我只能猜测没有任何内容:no_middlename将其返回到原始for循环中的调用。