- Mar 18, 2005
- 1,243
- 2
- 0
I've spent the last 3 days trying to make this work, ended up deleting about 5 pages worth of scripting becuase I just can't get it to work.
The idea here is to take a text file with 3 columns - Persons first name, ID and Group type - and run the script to read the group type and sort it while removing duplicates, then call up a second script to create groups from the sorted file while also creating user accounts from the first column of the original text. At the end the users get added to the already created groups and it goes back to the first script.
@Echo Off
**********************************************
Echo 'Backing up text1.txt to text1.t2t in case I screw this up'
Pause
@Echo Off
Copy text1.txt text1.t2t
@Echo Off
Echo Create Groups and Users files.
Echo.
FOR /F "tokens=3" %%i IN (text1.txt) DO Echo >>Groups1.txt %%i
FOR /F "tokens=1" %%f IN (text1.txt) DO Echo >>Users1.txt %%f
Sort Groups.txt > SortedGroups.txt
Call Groupcreation1.bat
Pause
The groupcreation batch file is below **************************
@Echo Off
ECHO creating groups
ECHO.
FOR /F %%i in (groups1.txt) DO NET LOCALGROUP %%i /ADD
REM show groups
NET GROUPS |MORE
ECHO create users
ECHO.
FOR /F "tokens=1" %%i IN (users1.txt) DO NET USER %%i %%j /ADD
ECHO finished creating users.
ECHO adding users to groups.
ECHO.
FOR /F "tokens=1,3" %%i IN (text1.txt) DO NET LOCALGROUP %%i %%j /ADD
**************************
My biggest problems are, in the first script I can't figure out how to have it sort and ignore duplicates then properly call the next script. The second one it seems to add the users and groups twice, I'm not sure exactly how to have it go back to the other script as I've never got that far.
Any insight, help, hell anything at all would be appreciated.
The idea here is to take a text file with 3 columns - Persons first name, ID and Group type - and run the script to read the group type and sort it while removing duplicates, then call up a second script to create groups from the sorted file while also creating user accounts from the first column of the original text. At the end the users get added to the already created groups and it goes back to the first script.
@Echo Off
**********************************************
Echo 'Backing up text1.txt to text1.t2t in case I screw this up'
Pause
@Echo Off
Copy text1.txt text1.t2t
@Echo Off
Echo Create Groups and Users files.
Echo.
FOR /F "tokens=3" %%i IN (text1.txt) DO Echo >>Groups1.txt %%i
FOR /F "tokens=1" %%f IN (text1.txt) DO Echo >>Users1.txt %%f
Sort Groups.txt > SortedGroups.txt
Call Groupcreation1.bat
Pause
The groupcreation batch file is below **************************
@Echo Off
ECHO creating groups
ECHO.
FOR /F %%i in (groups1.txt) DO NET LOCALGROUP %%i /ADD
REM show groups
NET GROUPS |MORE
ECHO create users
ECHO.
FOR /F "tokens=1" %%i IN (users1.txt) DO NET USER %%i %%j /ADD
ECHO finished creating users.
ECHO adding users to groups.
ECHO.
FOR /F "tokens=1,3" %%i IN (text1.txt) DO NET LOCALGROUP %%i %%j /ADD
**************************
My biggest problems are, in the first script I can't figure out how to have it sort and ignore duplicates then properly call the next script. The second one it seems to add the users and groups twice, I'm not sure exactly how to have it go back to the other script as I've never got that far.
Any insight, help, hell anything at all would be appreciated.
