NinjaTek

NinjaTek

Wednesday, December 29, 2010

Give Users Full Control & Ownership Permissions to their Subfolders on a Share

Here’s a great script to give user’s full control and ownership of their subfolders in a share (with their username as the subfolder name).

Problem:
You have a share on SERVER called USERS that has your user’s folders (their username = subfolder name). The problem is that none of the users have permissions to their folders…

\\SERVER\USERS\JBond
\\SERVER\USERS\BGates
\\SERVER\USERS\SBallmer

The Users folder is located at C:\USERS\

Solution:
  • Create a batch file called UserFolderOwner.bat containing the following code:

@echo off
if {%1}=={} @echo Syntax: UserFolderOwner FolderPath&goto :EOF
if not exist %1 @echo UserFolderOwner - %1 not found&goto :EOF
pushd %1
for /f "Tokens=*" %%a in ('dir %1 /b /AD') do (
 @echo y| cacls "%%a" /t /e /c /g "%UserDomain%\%%a":F
 subinacl /subdirectories "%%a" /setowner="%UserDomain%\%%a"
 subinacl /subdirectories "%%a/*.*" /setowner="%UserDomain%\%%a"
)
popd

The Batch file UserFolderOwner.bat uses SubInAcl to give the user Ownership of the subfolder and CACLS to set Full Control permissions

To run the batch file from CMD type: 

UserFolderOwner.bat ParentFolder

Where ParentFolder is the path to the Folder (C:\USERS)

Let that run and you will have saved yourself hours of manual labour…


Many Thanks to Jerold Schulman at WindowsITPro.com for creating this great script! (JSI Tip 8648).

2 comments:

  1. I want this to work on the Z Share, how do I do that? I've already tried UserFolderOwner.bat (Z:) and that didn't work.

    Please reply ASAP. Thanks.

    ReplyDelete