我正在尝试完成一项家庭作业脚本作业,我基本上对此一无所知,需要找到/研究脚本的修复程序。我需要运行的脚本查看一个三列(名称、ID、部门)文件(我得到的),并且应该创建新的组和用户并将用户分配给正确的组。每个组只能创建一次。我的问题是使用带有令牌的 FOR /f 命令。
文件 1
@ECHO OFF
SET /p userfFile="what is the file that contains new hires: "
REM Loop through the lines of the file
REM and copy the the department names to a new file
FOR /f "tokens=3 skip=4" %%b IN (%userfFile%) DO ECHO %%b >> Department.txt
REM sort the file back into itself
sort Department.txt /0 Department.txt
REM a variable to keep track of the groups that have neen created
SET LastGroupCreated=None
FOR /f %%a IN (Department.txt) DO CALL CUG
FOR /f "tokens=2,3 skip=4" %%A IN (%userfFile%) DO CALL
REM Clean Up
DEL Department.txt
SET userfFile=
文件 2“CUG”
REM Have we already processed this name (%1) ?
IF "%LastGroupCreated%"=="%1" GOTO :EOF
REM Not Processed, so create and update the variable
NET LOCALGROUP /ADD %1
SET LastGroupCreated=%1
我相信文件 CUG 很好,但文件一总是给我错误。如果有人可以帮助我,我将不胜感激。我已经尝试了所有我能想到的并且被卡住了
干杯
詹姆士