Jump to content

Recommended Posts

Posted

Does anyone have, or can anyone quickly knock up for me a script to create a folder in a number of folders and set the permissions on that folder?

 

Heres what I need...

 

Our directory structure is like this,

 

\\servername\userdirs\students\intakeyear\studentusername\Files\

 

I need a folder called Cakewalk set up in every one of our students Files folder with our students global security group set to deny full control.

 

 

Im sure one of you clever people can do this in a few seconds!

 

Thanks

James

Posted

This should be a starting point. Look up the syntax for CACLS to make sure it does what you need. Alternatively, use ICACLS as it has more features.

 

for /d %%d in (*.) do (
call :setperms %%d
)
goto :eof

:setperms
echo Setting permission on folder %1
cacls %1 /t /p %1:C
echo.

 

The *. assumes that this script is running from the root folder of the students - you should change it to an absolute path to be sure.

  • Thanks 1
Posted (edited)

Apologies, it was a bit rushed. I misunderstood what you wanted to do.

 

Try this.

 

 

set rootpath=\\servername\userdirs\students\intakeyear

for /d %%d in (%rootpath%\*.) do (
:: for every subfolder folder in intakeyear, call a subroutine to make a new folder
call :makefolder %%d
)
goto :eof

:makefolder
echo.
echo Creating Cakewalk subfolder in %1
md %1\Cakewalk
echo.

 

If your parent permissions are set to deny full control, you shouldn't need to worry about inherited permissions.

 

To test it does what you expect, put a 'PAUSE' statement after 'call :makefolder %%d'

Edited by jinnantonnixx
  • Thanks 1
Posted

This is exactly what I need but this is creating a folder called cakewalk in \\servername\userdirs\students\intakeyear\studentusername\

 

I need it to create the folder in \\servername\userdirs\students\intakeyear\studentusername\files

 

The files folder is already there and has documents and other folders in it

 

I also need to set the permissions on the folder to deny for the group gsgstudents

 

 

Thanks for your help with this.

Posted (edited)

Oops My goof, just change the first line to

set rootpath=\\servername\userdirs\students\intakeyear\files

 

I think you wanted to deny group gsgstudents access to this folder? The cacls line sets the security. It will deny the group gsgstudents rights to the folder. If you want different rights, you can configure cacls to do what you need.

 

Here's the lowdown on cacls.

Cacls - Modify Access Control List

 

 

...

So this should work.

 

set rootpath=\\servername\userdirs\students\intakeyear\files

for /d %%d in (%rootpath%\*.) do (
:: for every subfolder folder in intakeyear, call a subroutine to make a new folder
call :makefolder %%d
)
goto :eof

:makefolder
echo.
echo Creating Cakewalk subfolder in %1
md %1\Cakewalk
echo Setting permissions on folder %1\Cakewalk
echo Y | cacls %1\Cakewalk /d gsgstudents
echo.

 

The 'echo Y | ' bit is needed as cacls asks 'Are you sure?' when you run the command. We're piping a 'Y' character to the command, effectively pressing the Y key.

Edited by jinnantonnixx

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...