Create Folder with NTFS Permissions

by Jun 3, 2015

Often, you may need to create a new folder and also set NTFS permissions for the folder.

Here is a simple example that creates a new folder and illustrates how you can add new permissions to the existing permissions:

$Path = 'c:\protectedFolder'

# create new folder
$null = New-Item -Path $Path -ItemType Directory

# get permissions
$acl = Get-Acl -Path $path

# add a new permission
$permission = 'Everyone', 'FullControl', 'ContainerInherit, ObjectInherit', 'None', 'Allow'
$rule = New-Object -TypeName System.Security.AccessControl.FileSystemAccessRule -ArgumentList $permission
$acl.SetAccessRule($rule)

# add another new permission
# WARNING: Replace username "Tobias" with the user name or group that you want to grant permissions
$permission = 'Tobias', 'FullControl', 'ContainerInherit, ObjectInherit', 'None', 'Allow'
$rule = New-Object -TypeName System.Security.AccessControl.FileSystemAccessRule -ArgumentList $permission
$acl.SetAccessRule($rule)

# set new permissions
$acl | Set-Acl -Path $path 

Twitter This Tip! ReTweet this Tip!