Active Directory security groups are used to grant users’ permissions to various domain services and resources. Therefore, to understand what permissions are assigned to a specific user in the AD domain, it is enough to look at the groups in which the user account is a member of.
The easiest and most clear way to get a list of user groups in AD is to use the graphical snap-in Active Directory Users & Computers (ADUC).
- Run the dsa.msc snap-in;
- Right-click on the domain root and select Find;
- Enter a username and click Find Now;
- Open the user properties and go to the Member of tab;
- This tab lists the groups the selected user is a member of.
You can also check Active Directory group membership through command-line. Run the command:
net user USERNAME /domain
As you can see, the command output contains the domain (Global Group memberships) and local groups (Local Group Memberships) of the user.
Using the following command, you can list the security groups that your account is a member of:
whoami /groups
The main drawback of the methods described above is that the nested AD groups are not displayed (when the group is a member of other security groups).
You can display a full list of user groups (including nested ones) using the dsget tool. Instead of a username, you need to specify its distinguishedName:
dsget user " CN=Jon Brion,OU=Users,OU=UK,DC=theitbros,DC=com" -memberof -expand
Using dsquery and net group commands, you can display the members of a specific AD group:
dsquery group -name "AllowUSB" | dsget group -members
or:
net group "AllowUSB" /domain
You can also check user AD group membership using the PowerShell cmdlets: Get-AdUser, Get-ADPrincipalGroupMembership. To do this, you need the PowerShell Active Directory module installed on your computer.
Display only usernames that are added to the specific AD group (including nested groups):
Import-module Activedirectory Get-ADGroupMember -Identity AllowUSB -Recursive | ft name
Display group members with detailed information for each of them:
Get-ADGroupMember -Identity AllowUSB | foreach { Get-ADUser $_ -Properties * }
The list of Active Directory groups in which the user is a member of can be displayed using the following commands:
Get-ADPrincipalGroupMembership jbrion | Select name
or
Get-ADUser jbrion -Properties Memberof | Select -ExpandProperty memberOf
You can use the filter by group name:
Get-ADPrincipalGroupMembership jbrion | where {$_ -like "*allow*"} | Sort-Object | select -ExpandProperty name
The following PowerShell script template can be used to check user’s membership in a specific Active Directory group and perform some actions depending on group membership (the group name must be specified between the * characters):
$group = “*AllowUSB*”
$user = “jbrion”
if ((Get-ADUser $user -Properties memberof).memberof -like $group )
{
# If the user is a member of a group
echo “True”
}
Else
{
# User not in group
echo “False”
}
- Fix Trust relationship Failed Issue Without Domain Rejoining - January 21, 2021
- How to Login with a Local Windows Account Instead of Domain Account? - January 20, 2021
- How to View Saved Wi-Fi Passwords on Windows 10? - January 15, 2021
Thank you. This is just what I needed however during testing it became clear that you may need to use a wildcard since the Get-ADUser cmdlet will return the distinguished name of the group which contains superfluous verbiage, eg, CN=GroupName,OU=Marketing,DC=Domain,DC=Subdomain,DC=com.
Thus, using the -like operator requires that you enclose the search term like such:
if ((Get-ADUser $user -Properties memberof).memberof -like “*$group*” )