A quick and nice script to get all groups and their member users exported in PowerShell… you might need that for multiple reasons, and getting them quick is a nice thing…

Today I needed that for a customer who asked for it because he was cleaning his 1000 users active directory, and lucky me, the force of PowerShell can just do anything!

Script:

$groups = get-adgroup -filter *
foreach ($group in $groups)
{
    echo "Group: $group - Member list:"
    get-adgroupmember -identity "$group" | select Name, SamAccountName | ft -au
}

The above will just display the output on the screen, so in order to have it in a file, you can save the script to a file then pass it to Out-File with your desired file name…

Example:

Get-ADGroupsAndMembers.ps1 | Out-File c:\all_users_and_groups.csv

I have attached the script file (.ps1) into this post so you can quickly download it, have fun… 🙂

Get-ADGroupsAndMembers

No responses yet

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.