Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- :: Sean Reilly
- :: Student Number = 040884276
- :: Submitted Wednesday 26th July 2017
- @echo off
- ECHO "Welcome to CST8202 Lab 10 Script - Creation Version"
- ECHO "This script creates user group and folders based on file input"
- PAUSE
- :PROMPT:
- :: Prompt for a variable to set the name of the text file to be used
- ECHO "please enter the name of the text file to be used, do not include the file extension"
- SET /P reil0041-usrfile=
- :: Now redefining the variable %reil0041-usrfile% to contain the absolute path
- :: This absolute path will lead to the specified text file in C:
- SET reil0041-usrfile=C:\Scripts\17S\reil0041\%reil0041-usrfile%.txt
- :GROUP_EXTRACT_AND_CREATE:
- :: Now looking to extract the list of group names one at a time from the text file
- :: Duplicate checking will be on a name by name basis
- :: Before the each group is created we will check if it already exists
- :: FOR the list of group names in specified file
- :: DO a find in netlocalgroup for each name(supress the output)
- :: If the find doesn't work (the group doesn't exist)
- :: Create the group
- FOR /F "tokens=3 skip=4" %%G IN (%reil0041-usrfile%) DO NET LOCALGROUP | FIND "%%G" >NUL || NET LOCALGROUP /ADD %%G
- :USER_EXTRACT_AND_CREATE:
- :: Now looking extract the list of users one at a time from the text file and add to their groups
- :: There is no checking for duplicate users, there is a user id field to make them unique
- FOR /F "tokens=1 skip=4" %%U IN (%reil0041-usrfile%) DO NET USER /ADD %%U
- :USER_EXTRACT_+_GROUP_EXTRACT_AND_ADD:
- :: Now looking to add users to the groups
- :: Memory management is no concern
- FOR /F "tokens=1,3 skip=4" %%A IN (%reil0041-usrfile%) DO NET LOCALGROUP /ADD %%A %%B
- :: Now looking to create a user folder in C:\HOME for each user's employee id (username)
- FOR /F "tokens=2 skip=4" %%C IN (%reil0041-usrfile%) DO MKDIR C:\%%C
- ECHO This concludes the creating version of this script
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement