Set ACL through PowerShell

A few seconds ago I saw a tweet passing by telling me that SetACL had a new version.
That got me thinking… could I do some of the basics with PowerShell? Not that it would replace a great tool like SetACL, but what if I could type in the command in the same time it would take me to download and install SetACL?
And yes I could, as normally with PowerShell it would only take a simple command.

First, create a file or folder and set the appropriate ACL to it, for example through the GUI in Windows. Next, open a PowerShell window and enter the following command which will get the ACL from a target and put it into a variable:
$NewAcl = Get-ACL D:\Software

Now that we have a point of reference and saved it to a variable, we can use this information when setting the ACL on whatever target (and all it’s sub files and folders by using the –recurse parameter) we specify with the following command:
Get-ChildItem D:\Pictures -recurse | Set-ACL –ACLObject $NewACL

But what if you only want to set the ACL for specific files, for example all files with the .pptx extension?
Get-ChildItem D:\Pictures –recurse –include *.pptx –force | Set-ACL –ACLObject $NewACL

I would like to explain again that this would not be a replacement of a tool, since such a simple command can’t replace the full functionality of the SetACL tool.

Leave a Reply

Your email address will not be published. Required fields are marked *