Search code examples
powershellpermissionsaclfileserver

Getting and Error when changing an ACL via Powershell


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.


Solution

  • 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