Trouble deleting acl using RemoveAccessRule

Welcome Forums General PowerShell Q&A Trouble deleting acl using RemoveAccessRule

This topic contains 1 reply, has 1 voice, and was last updated by

2 years, 3 months ago.

  • Author
  • #61801

    Points: 0
    Rank: Member

    I'm new to playing around with acl's in the file system. I can add rights but I can't figure out how to remove acl's. Here is the code I have.

    $FolderPath = "\\filedirectory"
    $acl = get-acl $FolderPath
    #I use this to remove all acl's that are not inherited.  When I ouptut $acl.access it does remove them (in this case it just removes one security group with my test)
    $ACL.access | Where-Object {$_.isinherited -eq $false}  | %{ $ACL.RemoveAccessRule($_) }
    #I get the error when I set-acl.  
    set-acl -path $Folderpath -aclobject $ACL

    The error I gets is as follows:

    set-acl : AclObject At C:\Users\admin.isilver1\Documents\saveacl\restore_acl.ps1:405 char:9
    + set-acl -path $Folderpath -aclobject $ACL
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidArgument: (System.Collections.Hashtable:Hashtable) [Set-Acl], ArgumentException
    + FullyQualifiedErrorId : SetAcl_AclObject,Microsoft.PowerShell.Commands.SetAclCommand

    I have scurried the web for information with no luck. Any help would be great.

  • #61807

    Points: 0
    Rank: Member

    I've finally got it figured out. I knew posting it here would help. It turns out I use $acl variable for something else. After I changed the name it fixed the problem.

The topic ‘Trouble deleting acl using RemoveAccessRule’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort