I am trying to write a script in Powershell, that will find folders recursively and based on the folder name replace the ACL on the folder.
I have folders already with the correct permissions. These I use as template folders.
Folder1
Folder2
- Subfolder1
- Subfolder2
There are literally thousands of folders, all with the same names, and I would like to apply the same set of permissions to all of the like named folders. I have worked on tackling this a few different ways but I haven't found a good way to handle the sub-folders and recursion.
Here is a sample of the first way I tried to tackle this.
$Prop = Get-Acl "Template\Subfolder1"
$Engd = Get-Acl "Template\Subfolder2"
foreach ($file in $(Get-ChildItem Folder2 -recurse)) {
If ($_ = "Subfolder1") {
set-acl $_ $Prop
}
If ($_ = "Subfolder2") {
set-acl $_ $Engd
}
}
The further I get along with trying to write this the more I realize its going to be harder and harder. I have hundreds of folders named similar to Folder2 Folder3..... FolderN, all with the same folder structure and folder names inside. I just want something simple that will match a folder name and based on the name assign a certain predefined ACL.