- Open the PowerShell ISE on your domain controller and run the following PowerShell script:
import-module activedirectory
$Path = "C:\Temp\UserGroups.csv"
$username = "*"
$ADuser = Get-ADUser -filter {(Name -like $username -or SamAccountName -like $username) -and (Enabled -eq $true)}
$out = foreach($user in $ADuser) {
$groups = Get-ADPrincipalGroupMembership $user
foreach ($group in $groups){
$rec = New-Object PSObject
foreach($GP in $group.psobject.Properties) {
foreach($UP in $user.psobject.Properties) {
$rec | Add-Member -Type NoteProperty -Name ("U_" + $UP.Name) -Value $UP.value -Force
$rec | Add-Member -Type NoteProperty -Name ("G_" + $GP.Name) -Value $GP.value -Force
}
}
$rec|select U_Name, U_DistinguishedName,G_name,G_GroupCategory, G_GroupScope, G_distinguishedName
}
}
$out |Export-Csv $Path -NoTypeInformation
To list group names for single user identity only, replace "*" with the user account name.
For a summary report with less information, you can omit fields from the $rec|select statement.
You can leave only U_Name (or U_SamAccountName) and G_name (or G_SamAccountName) to get only User Name + Group Name summary.
- Review the .csv report:
- Run Netwrix Auditor. Navigate to “Reports” -> Click “Predefined” -> Expand the “Active Directory” section -> Go to “Active Directory – State-in-Time” -> Select “Group Members” -> Click “View”.
- Specify “Enabled” in the “Status” field and type “user” in the “Member Type” field -> Click “View Report”.
- Review your report:
- To export the report to a file, click the "Floppy" button and choose the desired format.