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

后端 未结 30 1741
攒了一身酷
攒了一身酷 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:36

    Get-Member is not for getting user's group membership. If you want to get a list of groups a user belongs to on the local system, you can do so by:

    $query = "ASSOCIATORS OF {Win32_Account.Name='DemoUser1',Domain='DomainName'} WHERE ResultRole=GroupComponent ResultClass=Win32_Account"
    
    Get-WMIObject -Query $query | Select Name
    

    In the above query, replace DemoUser1 with the username you want and the DomainName with either your local computer name or domain name.

提交回复
热议问题