← script library

Export Active Directory Users Group Memberships to CSV

Active DirectoryJanuary 5, 2025

Managing user group memberships in Active Directory is key to ensuring proper permission settings and security compliance. This PowerShell script allows administrators to export the group memberships of all users in Active Directory into a CSV file. This can be particularly useful for audits and reviews of user access rights. At ServerEngine, we empower IT professionals with effective tools for server management.

powershell
Import-Module ActiveDirectory

function Export-ADUserGroupMemberships {
    param (
        [string]$csvPath = "C:\Path\To\Your\ADUserGroupMemberships.csv"
    )
    $users = Get-ADUser -Filter * -Property SamAccountName
    $groupMemberships = foreach ($user in $users) {
        $groups = Get-ADUser -Identity $user.SamAccountName -Properties MemberOf | Select-Object -ExpandProperty MemberOf
        [PSCustomObject]@{
            UserName = $user.SamAccountName
            Groups = ($groups -join "; ")
        }
    }
    $groupMemberships | Export-Csv -Path $csvPath -NoTypeInformation
    Write-Host "Group memberships exported to $csvPath"
}

Export-ADUserGroupMemberships -csvPath "C:\Path\To\Your\ADUserGroupMemberships.csv"

Run it across your fleet

This script runs as-is on a single host. Paste it into ServerEngine to schedule it, run it on a whole server group in parallel, and keep the credentials out of the file — see the scripts documentation and the credential store.

Ready when you are.

Try ServerEngine free for 7 days.