How to get all groups that a user is a member of?

后端 未结 30 1723
攒了一身酷
攒了一身酷 2020-12-04 05:56

PowerShell\'s Get-ADGroupMember cmdlet returns members of a specific group. Is there a cmdlet or property to get all the groups that a particular user is a member of?

30条回答
  •  情话喂你
    2020-12-04 06:34

    Almost all above solutions used the ActiveDirecotry module which might not be available by default in most cases.

    I used below method. A bit indirect, but served my purpose.

    List all available groups

    Get-WmiObject -Class Win32_Group

    And then list the groups the user belongs to

    [System.Security.Principal.WindowsIdentity]::GetCurrent().Groups

    Comparison can then be done via checking through the SIDs. This works for the logged in user. Please correct me if I am wrong. Completely new to PowerShell, but had to get this done for a work commitment.

提交回复
热议问题