Link to home
Start Free TrialLog in
Avatar of AndyinJapan
AndyinJapanFlag for United States of America

asked on

Mass folder creation and permission set

Ive got an OU with 100 students and I want to have a separate folder for each user with the following permissions
Teachers group= read/write/delete on all folders
Students= read/write/delete on their own folder only

Any ideas how I can scrip this otherwise its a lot of typing?

Many thanks
Andy
Avatar of Lee W, MVP
Lee W, MVP
Flag of United States of America image

The following script must be run on the server.

Always run tests before implementing a script in production.
@echo off
 
Set ou1=TheOUWithYourStudents
Set dc1=domain
Set dc2=local
REM This assumes that all student folders are stored in X:\users - x:\users\jsmith, etc
Set PathToUsers=X:\Users
 
REM (NOTE this assumes your domain name is domain.local - DC1 is "domain" and DC2 is "local")
 
for /f "tokens=1 skip=2" %%a in ('dsquery * ou=%ou1%,dc=%dc1%,dc=%dc2% -attr SamAccountName') Do (
   If not exist "%pathtousers%\%%a" md "%pathtousers%\%%a"
   cacls "%pathtousers%\%%a" /t /c /g "teachers group":F %%a:f
   rem OPTIONAL: Share each user folder as hidden share with everyone granted access to the share
   rem NTFS permissions will enforce who is able to access the data.  
   rem If you don't want this, remove the NET SHARE line.
   net share %%a$="%pathtousers%\%%a"
)

Open in new window

Avatar of AndyinJapan

ASKER

Leew,

Hi there and thanks for your prompt reply!

Sorry, I sholuld have make it more clear but the folders are not made as I wanted to script that as well?

The actually path is OU=Y1,OU=Students,DC=bst,dc=local"
I would like the folders to be in H:\Students\Y6

Sorry......thanks again
Andy
Did you try modifying the script - you would set pathtousers=h:\students\y6 - the script I posted already created the folders if they don't exist.  The only other thing you would need to do is add the other OU line - i used variables, but you can just add it directly.
Hi again,

thanks for you help on this....

Am getting the following error
Invalid Character
Line 1
Char 1

code: 800A0408

If I take the @echo off part out it then read a error at line 7 char 19

Odd.....

Hey, thanks again for your help on this one

Andy
ASKER CERTIFIED SOLUTION
Avatar of Lee W, MVP
Lee W, MVP
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Why the B Grade?