'Finding Shared Network Folder and Active Directory Information

I have a script that I'm using to try to find Shared network folder and subfolder information such as the folder owner, AD groups associated to the Network shared folder or subfolder, AD group notes, AD group description, AD group manager, and AD group manager email.

I'm currently having a hard time trying to figure out why none of this data is showing when I export this to a .csv file. I would appreciate any help or guidance.

# Find the owner of the Network Folders and the AD Groups they got access to and the details of those AD Groups (name, description, managedby and ema $FolderPath = $DomainName =
Start-Transcript $PSScriptRoot\Transcript.txt

$FolderPath = "\\server\foldername"
$DomainName = "Domain"       # as in   Domain\ADGroupName

write-Host "Getting All the permissions of a Folder and its subfolder..."
$ACLS = @()
$Acls += Get-Item $FolderPath | get-acl
$ACLs += Get-ChildItem $FolderPath -Recurse -Directory

$results = @()

foreach($acl in $acls)
{
    $Domain = $DomainName.Split(".")[0]
    write-Host "  Getting Access ADGroup details"
    $AllDomainAccess = $acl.Access | Where-Object { $_.identityReference -like "$Domain\*" }

    foreach($DomainAccess in $AllDomainAccess)
    {
        $ADGroup = $null
        $ADGroup = get-ADGroup $($DomainAccess.IdentityReference).value.split("\")[-1] -Properties * -server $DomainName  -ea SilentlyContinue

        if($null -ne $ADGroup)
        {
            $data = '' | Select-Object FolderPath, FolderOwner, AccessGroup, AccessGroup_Description, AccessGroup_ManagedBy, AccessGroup_ManagerEmail
            $data.FolderPath = $acl.Path.split(":")[-1]
            $data.FolderOwner = $acl.Owner
            $data.AccessGroup = $ADGroup.Name
            $data.AccessGroup_Description = $ADGroup.Description
            $data.AccessGroup_ManagedBy = $ADGroup.ManagedBy
            $data.AccessGroup_ManagerEmail = $(get-aduser $($ADGroup.ManagedBy) -Properties mail).mail

            $results += $data
        }

}
}

$results | export-csv "$PSScriptRoot\NetworkFolderPermissions.csv" -NoTypeInformation
write-Host "Saved the results in $PSScriptRoot\NetworkFolderPermissions.csv" -ForegroundColor Green

Stop-Transcript


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source