0

I have to create a set of folders based on an address list and then configure the permissions in active directory. Creating the folders and subfolders works for me, I adapted a few lines I found online:

This creates the folders based on the address list.

$FolderNames = Get-Content -Path "E:\Data\addresses.txt"
$DirectoryPath = "E:\Data\buildings"
 
ForEach ($FolderName in $FolderNames) 
{
    New-Item -ItemType Directory -Path (Join-Path -Path $DirectoryPath -ChildPath $FolderName)
}

This creates the subfolders

$FolderNames = "E:\Data\addresses.txt"
New-item "E:\Data\buildings\$env:foldernames\*" -Name "Patrimonium" -ItemType Directory
New-item "E:\Data\buildings\$env:foldernames\*" -Name "Social Services" -ItemType Directory
New-item "E:\Data\buildings\$env:foldernames\*" -Name "Administration" -ItemType Directory
New-item "E:\Data\buildings\$env:foldernames\*" -Name "Patrimonium\subfolder1" -ItemType Directory
New-item "E:\Data\buildings\$env:foldernames\*" -Name "Patrimonium\subfolder2" -ItemType Directory
New-item "E:\Data\buildings\$env:foldernames\*" -Name "Social Services\subfolder1" -ItemType Directory
New-item "E:\Data\buildings\$env:foldernames\*" -Name "Social Services\subfolder2" -ItemType Directory
New-item "E:\Data\buildings\$env:foldernames\*" -Name "Administration\subfolder" -ItemType Directory
New-item "E:\Data\buildings\$env:foldernames\*" -Name "Administration\subfolder2" -ItemType Directory

So now I want to disabele inheritance and set an ACL for every subfolder named "Patrimonium", "Social Services", "Administration". Every folder has it's own security group. The subfolders below that need to inherit permissions. Honestly I don't know where to start. Is it even possible?

3
  • What part do you not know where to start at? The nice thing about scripting is that it'll let you do multiple discrete steps just by lining up commands like you've don already. I think your steps are going to start with Get-ChildItem | Where $_.name -like "Patrimonium" | set-acl... Commented Oct 31, 2023 at 14:16
  • I tried with get-childitem but it doesn't return the full directory so I can't port it to set-acl. It finds the item with the name, and also the directory that it's in but they're 2 separate objects.
    – Marin
    Commented Nov 6, 2023 at 10:54
  • You can filter for objects and folders in powershell, and you can also select parent folders, if that's what you're looking for. Re-reading your question, that part is unclear: Do you want to Set-ACL on the child folders named that, or do you want to set the permissions on the PARENT of the folders with that name? Regardless, here's some places these questions were already asked and answered: stackoverflow.com/questions/9725521/… and stackoverflow.com/questions/3085295/… Commented Nov 6, 2023 at 15:14

0

You must log in to answer this question.