Setting NTFS Permissions With Powershell

此生再无相见时 提交于 2019-12-06 08:38:36

问题


Using the following powershell I have set the NTFS Permissions for a folder for full control. For some reason this is only applying to the folder and not its contents. I followed the instructions located here

$username = "exampleuser"

$permissionArgs = "domain\$username", "FullControl", "allow"
$permissionRule = New-Object System.Security.AccessControl.FileSystemAccessRule $permissionArgs
$acl = Get-Acl 'C:\Users\username1\Desktop\TESTING2'
$acl.SetAccessRule($permissionRule)
Set-ACL -Path 'C:\Users\username1\Desktop\TESTING2' -AclObject $acl

When I use CACLS to see the permissions I get the following output. (usernames+domain blurred)

Can anyone advise how to make the first user listed have the same permissions as the last?


回答1:


You need to include the inheritance parameter while definig the ACL rule like the below one.

$Folderpath='Destination Folder'
$user_account='User Acccount'
$Acl = Get-Acl $Folderpath
$Ar = New-Object system.Security.AccessControl.FileSystemAccessRule($user_account, "FullControl", "ContainerInherit, ObjectInherit", "None", "Allow")
$Acl.Setaccessrule($Ar)
Set-Acl $Folderpath $Acl

Hope this HElps.



来源:https://stackoverflow.com/questions/40336969/setting-ntfs-permissions-with-powershell

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!