Script to get list all users and nested users from a list of groups to csv


  • Hi,

    I'm trying to get a script to help with auditing our security groups. The script to get all the users

    and users from nested groups and output it to a csv. Also i need the output to include

    security groups that have no users. So far the script gives most of what i needed but i'm not sure how to

    query the nested groups and write the output for security groups with no users.

    $groups = Get-Content C:\temp\grouplist.txt $results = foreach ($group in $groups) { $description = (Get-ADGroup $group -Properties description).description $members = Get-ADGroupMember $group -recursive | get-adobject -properties whencreated | select name, whencreated, @{n='GroupName';e={$group}}, @{n='Description';e={$description}} if (-not $members) { Write-Warning "Group '$group' has no members" [pscustomobject]@{ Name = 'No Members' WhenCreated = '' GroupName = $group Description = $description } } else { $members } } $results $results | Export-csv C:\temp\grouplistresult.csv -NoTypeInformation

    Monday, May 20, 2019 12:37 PM

All replies