At my job we have hundreds of AD groups that we add users to to give them access to folders. For each folder/group of folders we give access to there is supposed to be a read, write, and modify group. A lot of those are missing (some just have one or two out of three).
I want to write a script (or to even know if it is possible) that will get the folders associated with a group so that I can add in the missing ones. There are thousands (maybe 10s of thousands) of subdirectories and files on our shared drives so recursively searching through them for each group is not a good use of my time. Is it realistic to recursively search it once and place each folder(s) and group into a csv? Or is there another language I can use to get this information?
If I have failed to provide anything let me know! I will put my code for adding in the missing groups below
Import-Module ActiveDirectory
$ou1 = "OU=redacted,OU=redacted,OU=redacted,OU=redacted,DC=redacted,DC=redacted"
$ou2 = "OU=redacted,OU=redacted,OU=redacted,OU=redacted,DC=redacted,DC=redacted"
foreach ($ou in ($ou1, $ou2)) {
$groups = Get-ADGroup -Filter * -SearchBase $ou | Sort-Object -Property Name
foreach ($current in $groups) {
$groupName = $current.Name
$suffixes = $groupName -split '_|-'
$missingGroups = @()
if (-not ($suffixes -contains 'R')) {
$missingGroups += $groupName + '-R'
}
if (-not ($suffixes -contains 'W')) {
$missingGroups += $groupName + '-W'
}
if (-not ($suffixes -contains 'M')) {
$missingGroups += $groupName + '-M'
}
# Create missing groups here using $missingGroups array
$missingGroups = @()
}
}
The basic logic will be to run this to find what groups are missing, get the folders associated with ones that have the same name, and add the read, write, or modify permissions to that new group. Any help is appreciated!