Getting and Error when changing an ACL via Powershell

偶尔善良 提交于 2020-01-06 17:12:32

问题


I am working on a small script which mdifies the ACL on a folderby adding extra permissions; I adm getting the error while I execute "Set-ACL" command; please do let me know what I am doing wrong.

$AddAccessRule = New-Object security.accesscontrol.filesystemaccessrul("CREATOROWNER",@("ReadAndExecute,Synchronize"),"ContainerInherit,Objectinherit","Inheritonly","Allow")
$objacl = get-acl $FolderPath
$ObjAcl.AddAccessRule($AddAccessRule)
Set-acl $FolderPath $objacl

The follwoing error occurs , when i execute it;

Exception calling "AddAccessRule" with "1" argument(s): "Some or all identity references could not be translated." At C:\Users\kakulva\Desktop\Scripts\CreatorOwner\ACL.ps1:10 char:1 + $ObjAcl.AddAccessRule($AddAccessRule) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : IdentityNotMappedException

Let me know if any quetions or clarifications required.


回答1:


This works ( or at least doesn't return errors ):

$AddAccessRule = New-Object 'security.accesscontrol.filesystemaccessrulE'("CREATOR OWNER",@("ReadAndExecute,Synchronize"),"ContainerInherit,Objectinherit","Inheritonly","Allow")
$objacl = get-acl C:\A
$ObjAcl.AddAccessRule($AddAccessRule)
Set-acl -PATH C:\A $objacl


来源:https://stackoverflow.com/questions/14402317/getting-and-error-when-changing-an-acl-via-powershell

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