I have a folder with lots of subfolders
- D:\Data\Subfolder1
- D:\Data\Subfolder2
- D:\Data\Subfolder3
- D:\Data\Subfolder4
- D:\Data\Subfolder5
- ...
I need to create three active directory groups for each subfolder like this.
- FS_Data-Subfolder1_Read
- FS_Data-Subfolder1_Change
- FS_Data-Subfolder1_Full
and after this is done i have to map folder, Activedirectory group, and permission.
To set the permission is the hard part. this is how far i got. i dont know how to bind the group to the permission and then apply it to the folder.
$SharePath = "\\fs\data\" $FSGroupPath = "OU=GROUPS,OU=Data,DC=DOMAIN,DC=LOCAL" Get-ChildItem $SharePath | ForEach-Object { $GroupNameRead = "FS_Data-" + $_ + "_Read" $GroupNameChange = "FS_Data-" + $_ + "_Change" $GroupNameFull = "FS_Data-" + $_ + "_Full" New-ADGroup -Name $GroupNameRead -DisplayName $GroupNameRead -GroupScope DomainLocal -GroupCategory Security -Path $FSGroupPath -Description "Ger Läs Rättigheter till sökväg: FS\Data\$_" New-ADGroup -Name $GroupNameChange -DisplayName $GroupNameChange -GroupScope DomainLocal -GroupCategory Security -Path $FSGroupPath -Description "Ger Ändra Rättigheter till sökväg: FS\Data\$_" New-ADGroup -Name $GroupNameFull -DisplayName $GroupNameFull -GroupScope DomainLocal -GroupCategory Security -Path $FSGroupPath -Description "Ger Fulla Rättigheter till sökväg: FS\Data\$_" $set_Group = $GroupNameFull $set_rights = Modify $acl = Get-Acl $SharePath $permission = $set_user,$set_rights,"Allow" $accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $permission $acl.SetAccessRule($accessRule) $acl | Set-Acl $SharePath }