Trouble deleting acl using RemoveAccessRule

This topic contains 1 reply, has 1 voice, and was last updated by Profile photo of Ilan Ilan 6 months, 2 weeks ago.

  • Author
    Posts
  • #61801
    Profile photo of Ilan
    Ilan
    Participant

    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
    Profile photo of Ilan
    Ilan
    Participant

    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.

You must be logged in to reply to this topic.