Share via

Problem with nested group displaying the users

André Borgeld 431 Reputation points
2023-01-26T12:12:03.0833333+00:00

This script (give me users and groups on a fileshare ACL) works now as expected only the 'Group Member' column shows the users in the first group and the nested group, like this:

Group Member

Jo Allen, Iris Bloom, DG_NESTED

Is there any way I can get the members of the Nested group in the same column (group member) too?


$FolderPath = dir -Directory -Path "\\DFS\share" -Force #-recurse mogelijk
 $Report = @()
 ForEach ($Folder in $FolderPath) {
     $Acl = Get-Acl -Path $Folder.FullName
     foreach ($Access in $acl.Access)
     {
         try{
             $GroupMember = Get-ADGroupMember ($Access.IdentityReference.Value -Replace $((Get-ADDomain).NetBIOSName)+'\\')
             $Properties = [ordered]@{'FolderName'=$Folder.FullName;'AD Group or User'=$Access.IdentityReference;'Permissions'=$Access.FileSystemRights;'Inherited'=$Access.IsInherited;'Group Member'=$GroupMember.name -join ','}
        }
        catch{
             $Properties = [ordered]@{'FolderName'=$Folder.FullName;'AD Group or User'=$Access.IdentityReference;'Permissions'=$Access.FileSystemRights;'Inherited'=$Access.IsInherited;'Group Member'=''}
        }
        $Report += New-Object -TypeName PSObject -Property $Properties
     }
 }
 $Report | Export-Csv -Delimiter ';' -path "C:\Temp\ExportshareACL.csv"
Windows for business | Windows Server | User experience | PowerShell
0 comments No comments

Answer accepted by question author

Rich Matheisen 48,116 Reputation points
2023-01-26T16:12:02.5466667+00:00

If I understand your requirement, it's to place all the members of all the groups in the property "AD Group or User" of the $Properties hashtable.

Have you tried adding the "-Recursive" switch to the Get-ADGroupMember cmdlet?

Was this answer helpful?

1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. André Borgeld 431 Reputation points
    2023-01-30T14:10:22.2733333+00:00

    Hey @Rich Matheisen

    I was a few days away. But when I saw your answers I already new that was the solution.

    Today I've added it and it gives me the information that I want.

    Indeed I was trying to get the group, users and nested group in that column. How easy life can be , it works.

    Kind regards,

    Andre

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.