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 - Deletion Version"
- ECHO "This script deletes user group and folders based on file input"
- ECHO "There will be a prompt to skip deleting user's folders and also groups"
- 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"
- ECHO "this file should be a source of employee names, employee ids, and groups called "Hires" "
- 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
- :CHOIX:
- :: Now providing the option to skip deleting the users's folder as well as groups
- :: Simple prompt for 1 of 2 paths, incorrect entry will re-run the prompt
- ECHO "please specify skipping or deleteting the users's folder"
- ECHO "please enter (skip or delete)
- SET /P choix=
- IF (%choix% == skip ) {
- ECHO "You selected to skip deletion of the folders and groups"
- PAUSE
- GOTO :SKIP:
- }
- IF (%choice% == delete ) {
- ECHO "You selected to run the delete script
- PAUSE
- GOTO :GROUP_EXTRACT_AND_DELETE:
- }
- :: Else case simple loop back to the beginning of this section
- ELSE {
- CLS
- GOTO :CHOIX:
- }
- :GROUP_EXTRACT_AND_DELETE:
- :: Now looking to extract the list of group names one at a time from the text file
- :: Duplicate checking will be on a group by group basis
- :: Before Deleting a given group we will make sure that it exists
- FOR /F "tokens=3 skip=4" %%G IN (%reil0041-usrfile%) DO NET LOCALGROUP | FIND "%%G" >NUL && NET LOCALGROUP /REMOVE
- :USER_FOLDER_EXTRACT_AND_DELETE:
- :: Now looking to extract and delete user folders (which are named from the employee id)
- FOR /F "tokens=2 skip=4" %%C IN (%reil0041-usrfile%) DO RMDIR C:\%%C
- :USER_EXTRACT_AND_DELETE:
- :SKIP:
- :: Now looking to delete the User profiles
- :: Now looking extract the list of users one at a time from the text file and remove them
- :: There will be a check to make sure that the user exists before attempting to remove them
- FOR /F "tokens=1 skip=4" %%U IN (%reil0041-usrfile%) DO NET USERS | FIND "%%U" >NUL && NET USER /REMOVE %%U
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement