How to find out what group a given user has?
groups
or
groups user
How to get all groups that a user is a member of?
Get-ADPrincipalGroupMembership will do this.
Get-ADPrincipalGroupMembership username | select name
name
----
Domain Users
Domain Computers
Workstation Admins
Company Users
Company Developers
AutomatedProcessingTeam
List all groups and their descriptions for a specific user in Active Directory using PowerShell
From Get-ADPrincipalGroupMembership
manual:
The Get-ADPrincipalGroupMembership cmdlet returns a default set of ADGroup property values. To retrieve additional ADGroup properties pass the ADGroups objects produced by this cmdlet through the pipline to Get-ADGroup. Specify the additional properties required from the group objects by passing the -Properties parameter to Get-ADGroup.
So, let’s do it!
import-module activedirectory
$username = Read-Host 'Please enter Username!'
Get-ADPrincipalGroupMembership $username | Get-ADGroup -Properties * | select name, description
Also, in this case it should be enough to specify name,description
instead of asterisk (*
). If this is a performance issue, replace it. I am leaving it at asterisk because you might later change your mind about which properties you need.
Finding what Groups/Distribution lists a specific user belongs to in active directory
This returns all the roles (Groups) that a user belongs to.
public string[] GetRolesForUser(DirectoryEntry user)
{
user.RefreshCache(new string[] { "tokenGroups" });
var irc = new IdentityReferenceCollection(user.Properties["tokenGroups"].Count);
foreach (byte[] sidBytes in user.Properties["tokenGroups"])
irc.Add(new SecurityIdentifier(sidBytes, 0));
var coll = new StringCollection();
irc = irc.Translate(typeof(NTAccount));
foreach (var ir in irc)
{
if (ir is NTAccount)
{
coll.Add(ir.ToString());
}
}
var accounts = new string[coll.Count];
coll.CopyTo(accounts, 0);
return accounts;
}
Related Topics
Delete the First Five Characters on Any Line of a Text File in Linux with Sed
Reliability of Linux Kernel Add_Timer at Resolution of One Jiffy
Where Are the Stacks for the Other Threads Located in a Process Virtual Address Space
How Does a Linux Socket Buffer Overflow
Convert Bash 'Ls' Output to JSON Array
Starting Point for Clock_Monotonic
Installing R from Cran Ubuntu Repository: No Public Key Error
How to Get Coordinates of Touchscreen Rawdata Using Linux
Why Does Unix While Read Not Read Last Line
How to Detect When Someone Opens the Slave Side of a Pty (Pseudo-Terminal) in Linux
Swift on Os X Compiling for Linux