Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. :: Sean Reilly
  2. :: Student Number = 040884276
  3. :: Submitted Wednesday 26th July 2017
  4.  
  5. @echo off
  6. ECHO "Welcome to CST8202 Lab 10 Script - Creation Version"
  7. ECHO "This script creates user group and folders based on file input"
  8. PAUSE
  9.  
  10. :PROMPT:
  11.  
  12. :: Prompt for a variable to set the name of the text file to be used
  13. ECHO "please enter the name of the text file to be used, do not include the file extension"
  14. SET /P reil0041-usrfile=
  15. :: Now redefining the variable %reil0041-usrfile% to contain the absolute path
  16. :: This absolute path will lead to the specified text file in C:
  17. SET reil0041-usrfile=C:\Scripts\17S\reil0041\%reil0041-usrfile%.txt
  18.  
  19.  
  20. :GROUP_EXTRACT_AND_CREATE:
  21.  
  22. :: Now looking to extract the list of group names one at a time from the text file
  23. :: Duplicate checking will be on a name by name basis
  24. :: Before the each group is created we will check if it already exists
  25. :: FOR the list of group names in specified file
  26. :: DO a find in netlocalgroup for each name(supress the output)
  27. :: If the find doesn't work (the group doesn't exist)
  28. :: Create the group
  29.  
  30. FOR /F "tokens=3 skip=4" %%G IN (%reil0041-usrfile%) DO NET LOCALGROUP | FIND "%%G" >NUL || NET LOCALGROUP /ADD %%G
  31.  
  32. :USER_EXTRACT_AND_CREATE:
  33.  
  34. :: Now looking extract the list of users one at a time from the text file and add to their groups
  35. :: There is no checking for duplicate users, there is a user id field to make them unique
  36.  
  37. FOR /F "tokens=1 skip=4" %%U IN (%reil0041-usrfile%) DO NET USER /ADD %%U
  38.  
  39. :USER_EXTRACT_+_GROUP_EXTRACT_AND_ADD:
  40.  
  41. :: Now looking to add users to the groups
  42. :: Memory management is no concern
  43.  
  44. FOR /F "tokens=1,3 skip=4" %%A IN (%reil0041-usrfile%) DO NET LOCALGROUP /ADD %%A %%B
  45.  
  46. :: Now looking to create a user folder in C:\HOME for each user's employee id (username)
  47.  
  48. FOR /F "tokens=2 skip=4" %%C IN (%reil0041-usrfile%) DO MKDIR C:\%%C
  49. ECHO This concludes the creating version of this script
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement