- Open the PowerShell ISE.
If you don't have the Active Directory module installed on your Windows machine, you need to download the correct Remote Server Administration Tools (RSAT) package for your OS.
To activate the module, use the import-module ActiveDirectorycommand from an elevated PowerShell prompt. - Run one of the following PowerShell scripts, specifying the AD user account name (samaccountname) you’re interested in and the path to export.
Import-Module ActiveDirectory
$UserName = “Administrator“
$ReportPath = “C:\data\ADUserGroups.csv“
Get-ADPrincipalGroupMembershipwindows $Username | select name, groupcategory, groupscope | export-CSV C:\data\ADUserGroups.csv
- Get-ADPrincipalGroupMembership cmdlet retrieves Active Directory group membership for the specified user. It displays information about each group, including the name, category (Security or Distribution), and scope (Global, Universal, or Domain Local). This cmdlet looks directly into the group’s memberOf property. The above script will generate output as a CSV file, using the export-CSV cmdlet with pipeline symbol, and open the file in MS Excel.
- The Get-ADUsercmdlet in Windows PowerShell can retrieve information about Active Directory users. It allows you to query many attributes of user objects stored in Active Directory. This cmdlet also works for any AD partition or an AD LDS (Lightweight Directory Services) Instance. The script below uses -Propertiesparameter and MemberOf as values to get a group list in LDIF format containing distinguished names of the groups. This method is not suitable for reporting as it gives the output in a distinguished name format by default:
Import-Module ActiveDirectory
$UserName = “Administrator“
$ReportPath = “C:\data\ADUserGroups.txt“
#-Identity parameter can be used, or only the value can be provided as $UserName
(Get-ADUser $UserName –Properties MemberOf | Select MemberOf).MemberOf |Out-File -FilePath $reportpath
If the Windows user logged in does not have the privileges to run the script, you need to provide the alternate credentials to run the script through -Credential parameter, which provides the authentication for PowerShell.
- Run Netwrix Auditor → Navigate to "Reports" → Expand the "Active Directory" section → Go to "Active Directory - State-in-Time" → Select "User Accounts - Group Membership"→ Click 'View." You can also search for group membership for a specific user.
- To save the report, click the "Export" button → Choose a format from the dropdown menu → Click "Save".