2017-05-26 20 views
0

添加本地主机\用户+读取权限的文件夹我想:我怎样才能在PowerShell中

$Folderpath='D:\DATA\' 
$user_account='USERS' 
$Acl = Get-Acl $Folderpath 
$Ar = New-Object system.Security.AccessControl.FileSystemAccessRule($user_account, "Read", "ContainerInherit, ObjectInherit", "None", "Allow") 
$Acl.Setaccessrule($Ar) 
Set-Acl $Folderpath $Acl 

我获得以下错误:

Set-Acl : The security identifier is not allowed to be the owner of this object.

我不希望用户拥有者寿,只有有READ。

+0

我不认为问题出在您的脚本上,而是该文件夹中已有的所有权。 – BenH

回答

1

如果使用File System Security PowerShell Module这个任务变得可以使用Add-NTFSAccess,其作用在一个更合乎逻辑的方式要容易得多:

Add-NTFSAccess -Path D:\DATA -Account 'LocalComputerName\Username' -AccessRights Read 

而且如果它是一个域组只是域名更换LocalComputerName