How to Get AD Groups for a User With PowerShell

Use PowerShell’s Get-ADPrincipalGroupMembership cmdlet to list an Active Directory user’s direct group memberships. The command below returns the group names, categories, and scopes for the account jdoe. If you also need security groups inherited through nesting, use Get-ADAccountAuthorizationGroup instead.

Get-ADPrincipalGroupMembership -Identity 'jdoe' |
    Sort-Object Name |
    Select-Object Name, GroupCategory, GroupScope

What PowerShell AD Group Queries Return

Active Directory membership can be direct or nested. If a user belongs to Helpdesk, and Helpdesk belongs to Support, the user has direct membership in Helpdesk and indirect membership in Support.

The right query also depends on the group category:

  • Security groups can be used to assign permissions.
  • Distribution groups organize recipients for email and are not security principals used to assign permissions.

A directory membership query and a check of the current Windows sign-in session answer different questions. Directory queries read AD; session commands inspect the security information already associated with that session.

The commands in this article target Active Directory Domain Services, usually called on-premises AD. They do not query Microsoft Entra ID cloud group memberships.

How to Get AD Groups for a User

The Active Directory module can return and export a user’s direct groups or authorization security groups, including nested memberships.

Step 1: Install and Import the Active Directory Module

  1. Open Windows PowerShell on a Windows computer with network access to your domain controllers. Connect to your organization’s network or VPN if necessary.
  2. Check whether the Active Directory module is installed:
Get-Module -ListAvailable ActiveDirectory

If the command returns an ActiveDirectory module entry, you can import it. If it returns nothing, install the appropriate management tools from an elevated PowerShell window.

On a supported Windows client with RSAT available:

Add-WindowsCapability -Online -Name 'Rsat.ActiveDirectory.DS-LDS.Tools~~~~0.0.1.0'

On Windows Server:

Install-WindowsFeature -Name RSAT-AD-PowerShell
  1. Import the Active Directory module into the PowerShell session:
Import-Module ActiveDirectory

Installing the tools requires local administrative rights. Reading ordinary AD group memberships generally does not require Domain Admin privileges; the querying account needs permission to read the relevant directory objects.

Step 2: Resolve the Correct User Account

  1. Set $UserId to the account’s sAMAccountName and $Server to a domain controller in that account’s domain. Replace the example values with your own:
$UserId = 'jdoe'
$Server = 'dc01.contoso.com'
$User = Get-ADUser -Identity $UserId -Server $Server -ErrorAction Stop
$User |
    Select-Object Name, SamAccountName, UserPrincipalName, DistinguishedName
  1. Confirm that the returned account is the person you intend to inspect.

The -Identity parameter accepts a sAMAccountName, distinguished name, GUID, or SID. Do not assume that a display name or email-style user principal name will resolve through -Identity.

Setting -Server explicitly also prevents a query from silently using an unintended domain context.

Step 3: Choose and Run the Membership Query

Choose the query by the membership scope you need.

You Need Cmdlet or Filter What It Returns
An ordinary group inventory Get-ADPrincipalGroupMembership Group objects for the selected user
Direct security groups only Get-ADPrincipalGroupMembership with a GroupCategory filter The security-group portion of that inventory
Security groups inherited through nesting Get-ADAccountAuthorizationGroup Group objects for an authorization-membership check
  1. Run the query for your required membership scope and store its results in $Groups.

Direct security and distribution groups:

$Groups = Get-ADPrincipalGroupMembership -Identity $User -Server $Server -ErrorAction Stop

Direct security groups only:

$Groups = Get-ADPrincipalGroupMembership -Identity $User -Server $Server -ErrorAction Stop |
    Where-Object { $_.GroupCategory -eq 'Security' }

Security groups including nested membership:

$Groups = Get-ADAccountAuthorizationGroup -Identity $User -Server $Server -ErrorAction Stop
  1. Sort $Groups by Name and display the selected group properties:
$Groups |
    Sort-Object Name |
    Select-Object Name, SamAccountName, GroupCategory, GroupScope, DistinguishedName

For a group-to-member lookup, consider -Recursive. That parameter belongs to other commands, such as Get-ADGroupMember, which starts with a group rather than a user.

Step 4: Export the User’s Groups to CSV

  1. Export $Groups to a CSV file in a writable working directory. Adding the account name makes the file useful when combining reports later:
$CsvPath = ".\$($User.SamAccountName)-ad-groups.csv"
$Groups |
    Sort-Object Name |
    Select-Object @{Name='User'; Expression={$User.SamAccountName}},
        Name, SamAccountName, GroupCategory, GroupScope, DistinguishedName |
    Export-Csv -Path $CsvPath -NoTypeInformation -Encoding UTF8
  1. Use Import-Csv to check the exported columns and sample records:
Import-Csv -Path $CsvPath |
    Select-Object -First 5

Export the group objects, not formatted console output. Putting Format-Table before Export-Csv exports formatting objects instead of the group properties you want.

Nested Groups, Other Domains, and Membership Tests

LDAP matching-rule queries, resource-context servers, credential prompts, and authorization-group SIDs address nested groups, other domains, and membership tests.

Find Nested Security and Distribution Groups

The LDAP example uses the user’s distinguished name in a group-membership filter. This performs the membership traversal on the directory server instead of downloading every object and walking the relationships locally.

The following example searches the selected domain’s naming context:

Import-Module ActiveDirectory
$Server = 'dc01.contoso.com'
$User = Get-ADUser -Identity 'jdoe' -Server $Server -ErrorAction Stop
$SearchBase = (Get-ADRootDSE -Server $Server -ErrorAction Stop).DefaultNamingContext
$EscapedDn = $User.DistinguishedName.Replace('\', '\5c')
$EscapedDn = $EscapedDn.Replace('*', '\2a').Replace('(', '\28').Replace(')', '\29')
$EscapedDn = $EscapedDn.Replace([string][char]0, '\00')
Get-ADGroup -Server $Server -SearchBase $SearchBase `
    -LDAPFilter "(member:1.2.840.113556.1.4.1941:=$EscapedDn)" `
    -ErrorAction Stop |
    Sort-Object Name |
    Select-Object Name, GroupCategory, GroupScope, DistinguishedName

The matching rule finds direct and indirect membership links. Escaping the distinguished name keeps special characters from changing the meaning of the LDAP filter.

This is not a complete forest-wide entitlement report. The results are limited to the selected search scope. Do not treat the LDAP matching-rule query’s output as interchangeable with an authorization-group query.

Query Domain-Local Groups in Another Domain

A user can belong to domain-local groups in a resource domain other than the account’s own domain. The example specifies separate domain controllers for the account domain and the resource domain:

Import-Module ActiveDirectory
Get-ADPrincipalGroupMembership -Identity 'jdoe' `
    -Server 'dc01.contoso.com' `
    -ResourceContextServer 'dc01.resources.contoso.com' `
    -ErrorAction Stop |
    Sort-Object Name |
    Select-Object Name, GroupCategory, GroupScope, DistinguishedName

Replace both controller names. The account server identifies the user; the resource-context server identifies the domain whose domain-local memberships you want to inspect.

Inspect the returned distinguished names to confirm that the groups belong to the intended resource domain. A successful query against the account’s home domain alone should not be treated as proof that no resource-domain memberships exist.

Query With Alternate Credentials

Use a credential prompt when your current account cannot read the target directory:

Import-Module ActiveDirectory
$Credential = Get-Credential
Get-ADPrincipalGroupMembership -Identity 'jdoe' `
    -Server 'dc01.contoso.com' `
    -Credential $Credential `
    -ErrorAction Stop |
    Sort-Object Name |
    Select-Object Name, GroupCategory, GroupScope, DistinguishedName

Enter an account authorized to query that domain. A credential prompt avoids embedding a password in the script, but it does not bypass directory permissions or fix network connectivity.

Check Whether a User Belongs to One Security Group

For a yes-or-no security membership test that includes nesting, compare the target group’s SID with the user’s authorization-group SIDs:

Import-Module ActiveDirectory
$Server = 'dc01.contoso.com'
$User = Get-ADUser -Identity 'jdoe' -Server $Server -ErrorAction Stop
$Group = Get-ADGroup -Identity 'VPN-Users' -Server $Server -ErrorAction Stop
if ($Group.GroupCategory -ne 'Security') {
    throw 'Choose a security group for this authorization-membership test.'
}
$MembershipSids = Get-ADAccountAuthorizationGroup -Identity $User `
    -Server $Server -ErrorAction Stop |
    ForEach-Object { $_.SID.Value }
$MembershipSids -contains $Group.SID.Value

True means the queried authorization-group set includes the target security group. False means it does not. Using SIDs avoids confusion between groups with similar names, and -ErrorAction Stop prevents a failed directory query from continuing into a misleading membership result.

For a direct-membership test, use Get-ADPrincipalGroupMembership as the source of the SID list instead.

Troubleshoot Missing AD Groups and Query Errors

Use the error or missing result to identify the problem before changing the query.

Symptom Likely Cause What to Do
“The term … is not recognized” Active Directory module is unavailable or not imported Install the AD management tools and import the module
“Cannot find an object with identity …” Wrong identifier, domain, or server Resolve the account with Get-ADUser against its domain
Server or global catalog cannot be contacted DNS, VPN, connectivity, AD Web Services, or global catalog availability Restore directory connectivity before interpreting the results
Nested groups are missing A direct-membership query was used Use an authorization-group query for nested security membership
Distribution groups are missing An authorization-group query was used Use a principal-membership or appropriately scoped LDAP query
The primary group is missing Membership was read from memberOf or ordinary membership links Use a query that includes the primary-group relationship

Resolve a User Principal Name With a Filter

An email-style identity is often a user principal name, not the account’s sAMAccountName. Search the UserPrincipalName attribute explicitly, require one matching user, and then retrieve that account’s groups:

Import-Module ActiveDirectory
$Server = 'dc01.contoso.com'
$Users = @(Get-ADUser -Server $Server `
    -Filter "UserPrincipalName -eq '[email protected]'" `
    -ErrorAction Stop)
if ($Users.Count -ne 1) {
    throw 'Expected exactly one matching user. Check the UPN and domain.'
}
Get-ADPrincipalGroupMembership -Identity $Users[0] `
    -Server $Server -ErrorAction Stop |
    Sort-Object Name |
    Select-Object Name, GroupCategory, GroupScope, DistinguishedName

A user principal name can differ from an email address. If the search returns no user, confirm the actual sign-in name rather than assuming the mailbox address is the correct identifier.

Understand the Limits of memberOf

The memberOf property is useful when you specifically want the user’s direct membership links:

Get-ADUser -Identity 'jdoe' -Server 'dc01.contoso.com' -Properties memberOf |
    Select-Object -ExpandProperty memberOf

The output contains group distinguished names. It does not expand nesting.

Avoid using that property alone for a security-membership audit.

Separate Connectivity Failures From Empty Results

An AD query needs more than a reachable hostname. The querying computer must be able to resolve and contact the relevant directory services, and the membership cmdlets must be able to reach a global catalog.

If the module imports but queries fail, check directory connectivity:

  • Confirm that the organizational VPN or network connection is active.
  • Confirm that the computer uses DNS capable of resolving the AD domain.
  • Target a known domain controller with -Server.
  • Have the directory administrator check AD Web Services and global catalog availability when the error identifies those services.

Do not suppress these errors and record an empty group list. A failed query and a successful query returning no matching groups are different outcomes.

Verify Your AD Group Results

A group membership list is not an effective-permissions report.

Membership can explain why access is possible, but actual access also depends on the resource’s permissions, deny entries, local groups, application rules, and the security context used to reach it.

Before relying on the result, check:

  • Account identity: The returned SamAccountName and distinguished name match the intended user.
  • Membership scope: The query includes the direct or nested relationships your task requires.
  • Group category: Distribution groups have not been mistaken for permission-bearing security groups.
  • Directory scope: The queried domain includes the relevant groups, including any resource-domain memberships.
  • Query success: The directory query completed without lookup or connectivity errors.
  • Report contents: The exported CSV contains group properties, not formatting metadata.

After a recent membership change, domain controllers can temporarily return different results while replication completes. Compare queries against the same controller when investigating that discrepancy.

For an access problem, keep the group inventory as evidence, then test the specific resource using a fresh user session. For an inventory task, retain the CSV together with the user identity, queried domain, and query type so that the report’s scope remains clear.

Frequently Asked Questions

How Do I Check the Current User’s Security Groups From Command Prompt?

Run the following command to display the group information in the current process’s access token:

whoami /groups

This includes security groups such as local and built-in groups, not just AD groups, and it does not list distribution groups. It reflects the existing sign-in session; after a membership change, sign out and sign back in to obtain a fresh interactive logon token.

Can I Check Another User’s Groups From Command Prompt?

Use the domain account command to display another user’s account details and listed memberships:

net user jdoe /domain

Treat the domain account command as an account summary rather than a complete recursive membership audit; PowerShell’s AD cmdlets provide more precise membership queries and exportable objects.

How Do I Extract the Users in an AD Group With PowerShell?

Use Get-ADGroupMember when your starting point is a group rather than a user; recursive group-to-user lookup is also implemented in the ADReportingTools source on PowerShell Gallery. The following command includes users reached through nested groups and excludes computers and other object types:

Get-ADGroupMember -Identity 'Helpdesk' -Recursive |
    Where-Object { $_.objectClass -eq 'user' } |
    Sort-Object Name |
    Select-Object Name, SamAccountName, DistinguishedName

Remove -Recursive when you want only users directly listed as members of the group.

How Can I Output an AD User’s Name and Group Memberships With PowerShell?

Use a calculated property to show the user’s name, account name, and group names in one result.
Get-ADUser -Identity ‘jdoe’ -Properties memberOf | Select-Object Name, SamAccountName, @{Name=’MemberOf’;Expression={($_.memberOf | Get-ADGroup | Select-Object -ExpandProperty Name) -join ‘,’}}
The calculation expands the membership collection into group names before combining them into the MemberOf field.