Question : Need script to allow me to change permissions on a folder full of user folders

I'm looking for a script that will read an .csv file I have which has a list of usernames in it which correspond with a folder with user folders with matching usernames. For example I have the Home folder which contains a folder for each user.

The script I've tried to use is giving me issues and I don't know how to correctly pull a variable from the .csv file to begin with.

The file with the username list is called users.csv

I need to go to each user folder, take ownership of it, and change the permissions to allow System:full, Creator Owner: full, Domain Admins:Full, and the specific user whos username matches the variable imputed from the .csv file to Full.

It then needs to change ownership back to the user given in the variable.

I was using the script below but it only seems to run the first Icacls command then start over, also this script doesn't pull from Users.csv.

set /p userDir=Enter the login of the user's directory you're modifying permissions for. (i.e. jDoe)
TAKEOWN /f "C:\test\%userDir%" /r /d y
ICACLS "C:\test\%userDir%" /reset /T
ICACLS "C:\test\%userDir%" /grant:r "domain\%userDir%":(OI)(CI)F
ICACLS "C:\test\%userDir%" /setowner "domain\%userDir%" /T

Answer : Need script to allow me to change permissions on a folder full of user folders

And here you are =)  Sorry for the long wait, I've been very busy at work ^^

~Q
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
::------------------------------------------------------------------------------------------------::
:: Script Name - TakeOwnership                                                                    ::
:: Purpose     - Take ownership of several directories using LCACS.                               ::
:: Version     - 1.0                                                                              ::
:: Assumptions - That the Machine is windows NT Based to use the windows NT command set           ::
::                                                                                                ::
:: (c) Copyright 2008-2010, Ben Personick, All Rights Reserved                                    ::
::------------------------------------------------------------------------------------------------::

:Begin
  ECHO Off
  SET ScriptName=TakeOwnership
  ECHO ---- Begining %ScriptName%... ----


::------------------------------------------------------------------------------------------------::
:: This section sets up default variable settings and sets the logging directory and file name.   ::
::------------------------------------------------------------------------------------------------::
:Start-Prep
	CALL :Start-Set-Date
	SET Preamble=%ScriptName% --
	::--------------------------------------------------------------------------------------------::
	:: Sets Relative Paths used to search later.												  ::
	::--------------------------------------------------------------------------------------------::
	REM -- Set Source Directory and File
	SET RFDir=C:\Admin\%ScriptName%
	SET RFFile=Name.csv
	REM -- Set Users Base Directory
	SET BaseDir=C:\test
	REM -- Set Users Domain
	SET Domain=ContossoCorp
	::--------------------------------------------------------------------------------------------::
	:: This Section Sets up logging variables.													  ::
	::--------------------------------------------------------------------------------------------::
	SET IDir=C:\Admin\%ScriptName%\Logs
	SET ILog=%ScriptName%_%TDate%_%TTime%.Log
	SET IDL=%IDir%\%ILog%
	::--------------------------------------------------------------------------------------------::
	:: This Section Creates Directories for Logging and other files								  ::
	::--------------------------------------------------------------------------------------------::
	:Start-Create-Directories
		For /F %%D IN ("%IDir%") DO CALL :Start-DIR-Loop %%D
		GOTO End-DIR-Loop
		:Start-DIR-Loop
			SET TDir=%1
			ECHO %Preamble% Checking For %TDir%
			IF EXIST %TDir% CALL :Start-Echo "%TDir% -- Found!"
			IF EXIST %TDir% GOTO :EOF
			ECHO %Preamble% Creating %TDir%
			MKDir %TDir%
			CALL :Start-Echo "Created %TDir%"
			GOTO :EOF
		:End-DIR-Loop
		CALL :Start-Echo "Dir-Loop Completed"
	:End-Create-Directories
	::--------------------------------------------------------------------------------------------::
	:: This Section Sets Default Values for match variables, don't change except for testing.	  ::
	::--------------------------------------------------------------------------------------------::
	REM None Needed.

:End-Prep

::------------------------------------------------------------------------------------------------::
:: This begins the meat of the batch file                                                         ::
::------------------------------------------------------------------------------------------------::
:Start-Main
	CALL :Start-Echo "Begining Main Processing"


	FOR /F "tokens=*" %%R IN ('TYPE "%RFDir%\%RFFile%"') DO Call :Start-Change-Owner-Loop "%%R"
	Goto End-Change-Owner-Loop
	:Start-Change-Owner-Loop
		SET TName=%~1
		CALL :Start-Echo "Temp Name = %TName%"
		CALL :Start-Echo "TAKEOWN /f %BaseDir%\%TName% /r /d y"
		TAKEOWN /f "%BaseDir%\%TName%" /r /d y
		CALL :Start-Echo "ICACLS %BaseDir%\%TName% /reset /T"
		ICACLS "%BaseDir%\%TName%" /reset /T
		CALL :Start-Echo "ICACLS %BaseDir%\%TName% /grant:r %domain%\%TName%:(OI)(CI)F"
		ICACLS "%BaseDir%\%TName%" /grant:r "%domain%\%TName%":(OI)(CI)F
		CALL :Start-Echo "ICACLS %BaseDir%\%TName% /setowner %domain%\%TName% /T"
		ICACLS "%BaseDir%\%TName%" /setowner "%domain%\%TName%" /T
		GOTO :EOF
	:End-Change-Owner-Loop
	
:End-Main
GOTO :End


GOTO End-Subs
GOTO :EOF
:Start-Subs
	GOTO :End-Set-Date
	:Start-Set-Date
		SET TDate=%date:~10,4%-%date:~4,2%-%date:~7,2%
		SET TTime=%Time:~0,2%.%Time:~3,2%.%Time:~6,2%
		GOTO :EOF
	:End-Set-Date
	GOTO End-Echo
	:Start-Echo
		Set TEcho=%~1
		ECHO %Preamble% %TEcho% --
		ECHO %Preamble% %TEcho% -- >> %IDL%
		GOTO :EOF
	:End-Echo

:End-Subs

:End
CALL :Start-Set-Date
CALL :Start-Echo "Batch Completed ON %TDate% AT %TTime%"
GOTO :EOF
Random Solutions  
 
programming4us programming4us