-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathCreate-FolderNTFSPermissions.ps1
More file actions
25 lines (18 loc) · 967 Bytes
/
Create-FolderNTFSPermissions.ps1
File metadata and controls
25 lines (18 loc) · 967 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<#Create Folder with NTFS Permissions
This example 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