Get the list of non-inherited folders

As i work on network share permissions, sometimes i get over burden when i get a such request to give permission on a folder which have lots of non-inherited sub-folders. So in that you should have a list or information of all sub-folders which have their own individual permissions and not inheriting from their parent folder.

So to reduce my burden i wrote a script which gives me a list of all folder which have not inheriting from their parent folder.

I kept one thing under consideration while writing it. When we disable inheritance from any folder we keep Administrator with Full Control to manage the folders. You can make the change if you use any other group or service account for the same.

Script



$path = "\\path\to\the\folder"
$dir = Get-ChildItem -Path $path -Recurse -ErrorAction SilentlyContinue

foreach ($line in $dir)
    {
$type = $line | Select-Object -Property Attributes -ExpandProperty Attributes
    if ($type -eq 'Directory')
        {
        $folders = $line.FullName
        
        foreach ($folder in $folders)
            {
            $access = Get-Acl $folder | Select-Object -Property Access -ExpandProperty Access
                foreach ($info in $access)
                {
                if ($info.IdentityReference -eq "BUILTIN\Administrators")
                    {
                    $inher = $info.IsInherited
                    if ($inher -eq $false)
                        {
                        Write-Host $folder
                        }
                    }
                }
            }
        }        
    }

0 comments:

Post a Comment