Admin Scripts: Create Folder with NTFS Permission using Windows Batch and ICACLS

This is Admin Script to create folders and subfolders and assigned with NTFS permission.

I notice that there is such request from a user in Technet Forum on how to generate folders with NTFS permission using script.

The request is to use VBScript, but I think for fast and simplified approach, Windows Batch for creating folder and ICACLS for NTFS permission are the easiest approach to complete this task.

Steps

  1. Save All Admin Scripts in the root of folders to be created

  2. Open Command Prompt in Administrator mode

  3. Execute “YLNotes__CreateFolderWithNtfsPerm.cmd”

  4. If you wish to save to a log file for review, pipe the command to log file.

C:\> YLNotes__CreateFolderWithNtfsPerm.cmd > log.txt

 

Sample Log

Processing Folder [1]
-------------------------------------------------------------------------
Path: [Folder 1\Folder 1.1\Folder 1.1.1]
ICACLS Permission
-------------------------------------------------------------------------
- Inheritance Value: r - remove all inherited ACEs
- NTFS Permission  : M - modify access
- Grant to         : users
ICACLS CMD
-------------------------------------------------------------------------
ICACLS "F:\YLNotes__CreateFolderWithPerm\Folder 1\Folder 1.1\Folder 1.1.1" /inheritance:r /grant "users:(CI)(OI)M"
processed file: F:\YLNotes__CreateFolderWithPerm\Folder 1\Folder 1.1\Folder 1.1.1
Successfully processed 1 files; Failed processing 0 files
=========================================================================
Processing Folder [2]
-------------------------------------------------------------------------
Path: [Folder 1\Folder 3]
ICACLS Permission
-------------------------------------------------------------------------
- Inheritance Value: r - remove all inherited ACEs
- NTFS Permission  : M - modify access
- Grant to         : users
ICACLS CMD
-------------------------------------------------------------------------
ICACLS "F:\YLNotes__CreateFolderWithPerm\Folder 1\Folder 3" /inheritance:r /grant "users:(CI)(OI)M"
processed file: F:\YLNotes__CreateFolderWithPerm\Folder 1\Folder 3
Successfully processed 1 files; Failed processing 0 files
=========================================================================
Processing Folder [3]
-------------------------------------------------------------------------
Path: [Folder 1\Folder 7\Folder 7.1]
ICACLS Permission
-------------------------------------------------------------------------
- Inheritance Value: r - remove all inherited ACEs
- NTFS Permission  : M - modify access
- Grant to         : users
ICACLS CMD
-------------------------------------------------------------------------
ICACLS "F:\YLNotes__CreateFolderWithPerm\Folder 1\Folder 7\Folder 7.1" /inheritance:r /grant "users:(CI)(OI)M"
processed file: F:\YLNotes__CreateFolderWithPerm\Folder 1\Folder 7\Folder 7.1
Successfully processed 1 files; Failed processing 0 files
=========================================================================
Processing Folder [4]
-------------------------------------------------------------------------
Path: [Folder 1\Folder 7\Folder PC#]
ICACLS Permission
-------------------------------------------------------------------------
- Inheritance Value: r - remove all inherited ACEs
- NTFS Permission  : M - modify access
- Grant to         : users
ICACLS CMD
-------------------------------------------------------------------------
ICACLS "F:\YLNotes__CreateFolderWithPerm\Folder 1\Folder 7\Folder PC#" /inheritance:r /grant "users:(CI)(OI)M"
processed file: F:\YLNotes__CreateFolderWithPerm\Folder 1\Folder 7\Folder PC#
Successfully processed 1 files; Failed processing 0 files
=========================================================================

 

How it works

  1. The script contain Folders Data File where the folders data to populated

  2. The output of the log file to be generated into text file FOLDERS_DATA.txt

The example of the contents:
r|M|users|Folder 1\Folder 1.1\Folder 1.1.1
r|M|users|Folder 1\Folder 3
r|M|users|Folder 1\Folder 7\Folder 7.1
r|M|users|Folder 1\Folder 7\Folder PC#

  1. The Folders Path is generated and NTFS assigned on the leave of the folders.

For example, “Folder 1\Folder 1.1\Folder 1.1.1”, NTFS to be assigned on last folder “Folder 1.1.1”

 

Admin Scripts

  1. Download YLNotes__CreateFolderWithNtfsPerm (78)

Leave a Reply

Your email address will not be published. Required fields are marked *

9 + eleven =

YLNotes: Yunlong Notes © 2017 Frontier Theme